在我的iOS应用程序中,我使用setInterval获取当前位置,我能够获取当前位置。
我的问题是,即使我的应用程序在进入后台时也需要获取当前位置并保存到数据库中?
有人能指导我怎么做吗?
我在app.js中的代码
Ti.App.addEventListener('pause', function(e) {
// register a background service. this JS will run when the app is backgrounded
//checking that switch is ON/OFF
if (Ti.App.Properties.getString('getLocation') == 'YES') {
//timer = setInterval(Titanium.Geolocation.addEventListener('location', locationCallBack1), 10000);
service = Ti.App.iOS.registerBackgroundService({
url : '/mainWindows/bg.js'
});
}
});提前谢谢。
发布于 2014-04-07 15:00:33
你可能想在appcelerator论坛上看看这篇文章:Location tracking in the background with iOS
它利用了iOS后台服务,在docs中对此进行了很好的解释
// The app is transtioning to background here
Ti.App.addEventListener('pause', function(e){
// Register background service
bgService = Ti.App.iOS.registerBackgroundService({ url: 'bgService.js' });
Ti.API.info("registered background service = "+ bgService);
});https://stackoverflow.com/questions/22862045
复制相似问题