下面的代码近乎没什么逻辑,但运行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
});
}
})
},
是怎么判断被杀掉的?
2,与开发工具的真机调试断开了
3,从任务列表中调出小程序到前台,报楼下的那个cmdid 1005,errCode -2错误
2、这个是会的
3、这个麻烦提供下相关的代码片段看下
2、当与开发工具断开的时候,手机中的小程序就停止了GPS获取
3、相关代码就是这个帖子中的代码了,其他的也没啥啊。
4、之前都是与调试工具连接的情况下或开启内存负载大的程序(比如王者之类的)后台小程序会被杀掉;昨天未与调试工具连接,直接在微信中找到测试的小程序运行,未开启内存负载大的程序,还未发现被杀的情况,容我再测测。
另外,打开手机,从运行程序列表中调出小程序,就报这个错误cmdid 1005,errCode -2![](http://mmbiz.qpic.cn/mmbiz_png/Zqh50TbxmvD4LTqKUlBmvanNbHicGmI4CqvCwmAweyw3CDnPPFHJPe8ec2r6ice3Df6bsS0wMHpiasMllib6aoYTzA/0?wx_fmt=png)
后台运行获取GPS信息,这个在小程序上基本实现不了。小程序不能永驻后台