在后台运行获取GPS信息,10几分钟后,就被杀死,是怎么回事儿
发布于 7 年前 作者 juanzeng 14318 次浏览 来自 问答

下面的代码近乎没什么逻辑,但运行10几分钟后,就被杀掉了是怎么回事儿?

手机:一加5

app.json里设置了:

“requiredBackgroundModes”:[“location”],

“permission”:{

“scope.userLocation”:{

“desc”“你的位置信息将用于 GPS信息获取”

}

}

wx.startLocationUpdateBackground({

success:function(res){

var dateline = Date.now();

dateline = util.formatTime(newDate(dateline));

var msg = dateline + ’ 开启持续定位,成功’

textContent.unshift(msg);

thisPage.setData({

textContent: textContent

});

wx.onLocationChange(function (res) {

var dateline = Date.now();

dateline = util.formatTime(newDate(dateline));

var msg = dateline+" 纬度:" + res.latitude + “\n经度:” + res.longitude + ‘,速度:’ + res.speed + ‘,高度:’ + res.altitude;

console.log(msg);

if (textContent.length >= 50) textContent.pop();

textContent.unshift(msg);

thisPage.setData({

textContent: textContent

});

})

},

fail: function (res){

var dateline = Date.now();

dateline = util.formatTime(newDate(dateline));

var msg = dateline + ’ 开启持续定位,失败’

textContent.unshift(msg);

thisPage.setData({

textContent: textContent

});

}

})

},

3 回复

是怎么判断被杀掉的?

后台运行获取GPS信息,这个在小程序上基本实现不了。小程序不能永驻后台

另外,打开手机,从运行程序列表中调出小程序,就报这个错误cmdid 1005,errCode -2

回到顶部