我有一个注册iOS后台服务的Titanium应用程序,它每30秒记录一次设备的GPS数据。我已经将它注册为定位服务,这应该可以防止它在10分钟后停止,但它不起作用。以下是我的tiapp.xml的相关部分:
<ios>
<plist>
<dict>
<key>UISupportedInterfaceOrientations~iphone</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>gps</string>
<string>location-services</string>
</array>
</dict>
</plist>
</ios>下面是我如何在alloy.js中注册它:
if(utils.ios) {
console.log('registering ios background service');
Ti.App.iOS.registerBackgroundService({ url: 'tracking/backgroundService.js' });
}以及后台服务本身:
var timeout = constants.tracking.interval * 1000;
console.log('starting background gps tracking');
setInterval(function() {
var user = settings.user();
if(user && user.password) {
//user is logged in, let's track them.
gpsTracking.track();
}
else {
console.log('user is not logged in so not tracking');
}
}, timeout);这是在iPhone模拟器上测试的,我还没有在实际的iOS设备上测试过,因为开发人员站点仍然关闭,所以我无法创建配置文件。
我检查了build文件夹中的info.plist,它正确地添加了UIBackgroundModes和UIRequiredDeviceCapabilities的键/数组值,所以我不确定下一步要检查什么。
有什么想法吗?
发布于 2013-08-03 16:36:50
请参阅Mr.Chris的答案here。我来给你描述一下。
Here是一个很好的资源,可以用来了解应用程序如何与后台交互。只有几种不同类型的应用程序被允许在后台运行(并执行代码)以获得额外的时间。(我认为正常的限制大约是10分钟)。
在后台向用户播放音频内容的
对某些类型的后台执行的支持必须由使用它们的应用程序提前声明。应用程序使用其Info.plist文件声明对服务的支持。将UIBackgroundModes密钥添加到Info.plist文件中,并将其值设置为包含一个或多个以下字符串的数组:
因此,从build文件夹中获取info.plist文件,并将其放入项目的根目录中。然后按照上面描述的那样编辑它。希望这能有所帮助!
发布于 2015-10-22 16:58:00
我面临着同样的问题,钛似乎有一个全球定位系统的缓存逻辑,无法获得实际的纬度和longitude.Also遇到的问题像你一样,10分钟它停止了,如果我初始化系统的iOS地图,以获得成功的位置,钛的应用程序,它再次工作。很有灵性。经过长时间的调查和尝试。
最后,通过将accuracy设置为ACCURACY_NEAREST_TEN_METERS并使用location事件来解决此问题。现在我可以得到不断更新的GPS,精度也很好,5米。
Titanium.Geolocation.setAccuracy(ACCURACY_SET);
Ti.Geolocation.addEventListener('location',evtGpsResult);希望它能解决你的问题。
https://stackoverflow.com/questions/18027777
复制相似问题