react-native - 为什么世博会后台位置在 5 分钟后停止发送位置?
问题描述
我在 App.js 中定义了任务,一切正常!但 5 分钟后它停止发送位置,我不知道为什么。我正在使用这个包:https ://docs.expo.io/versions/latest/sdk/location/#background-location-methods
TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
console.log("Esta entrando al task")
if (error) {
console.log(error)
// Error occurred - check `error.message` for more details.
return;
}
if (data) {
const { locations } = data;
let getLastTime = await AsyncStorage.getItem('lastTime');
if(getLastTime){
let timeInterval = moment(new Date()).diff(getLastTime,'seconds')
if(timeInterval<=10) {
return
}
}
await LocationAPI.sendCurrentLocation(locations[0].coords).then(async res=>{
await AsyncStorage.setItem('lastTime', new Date().toString())
}).catch(err=>{
console.log(err)
console.log("en el task")
})
// do something with the locations captured in the background
}
});
解决方案
推荐阅读
- wordpress - 元素问题
- python - 使用 Python 获取 Zoom 会议的参与者
- java - 如何使用 Android Fat AAR 阻止对某些库的访问
- css - 背景图像在 iPad 上显示为放大
- node.js - Node 8 和 Node 10 在处理流和流事件方面的区别?
- python - 在 for 循环中调用函数以使用 sys.stdout 写入文本文件
- perl - 想要在 perl 中创建动态数组
- apache - 运行 1k 用户进行压力测试的最佳实践
- typescript - 从深度嵌套的对象结构中提取值
- typescript - nativescript - 您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件