我想在背景中每隔10秒跟踪用户坐标,所以我使用了cordova-plugin-mauron85-background-geolocation.It在前景或后台的android中工作得非常好但在IOS中它在后台不起作用(它有效)只在前景中)
在后台,它不会触发成功(SetLocationUpdates)函数,也不会给出错误,它不会触发错误函数。
这是我的config.xml
<plugin name="cordova-plugin-geolocation" source="npm" spec="2.4.1" />
<plugin name="cordova-plugin-mauron85-background-geolocation" spec="2.3.0">
<variable name="ALWAYS_USAGE_DESCRIPTION" value="xxx permission xx" />
</plugin>
<preference name="phonegap-version" value="cli-6.5.0" />
这是我的html页面代码
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript">
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady () {
backgroundGeolocation.configure(SetLocationUpdates, onError, {
desiredAccuracy: 10,
stationaryRadius:1,
distanceFilter: 1,
interval: 10000
});
backgroundGeolocation.start();
//backgroundGeolocation.switchMode(backgroundGeolocation.mode.FOREGROUND);
}
}
function onError(error) {
alert("error:"+error.message);
}
function SetLocationUpdates(position){
//store position to database via ajax call.....
它在前景中运行良好,所以我尝试在切换模式下强制它前景但是它不起作用
backgroundGeolocation.switchMode(backgroundGeolocation.mode.FOREGROUND,switchModesuccess, switchModefail);