停止位置更新应用时终止 [英] Stop location updates when app terminate
问题描述
我发展,你都在附近的地方提拔当它发送通知的应用程序。
我的问题是,当我去后台,然后我退出程序,我不希望定位服务工作时,应用程序无法正常工作(但我希望他们能够在后台运行)。
I'm developing an app which sends notifications when you are nearby of promoted places. My problem is when I go to background and then I quit the app, I don't want the location services working when the app doesn't work (but I want them to work in background).
我只看到3应用程序时应用程序被关闭而关闭GPS,我想知道他们是怎么做的,Facebook,谷歌地图和苹果地图,不四方,不实地考察...
I saw only 3 apps which close the gps when the app is closed and I want to know how they did that, Facebook, Google Maps and Apple Maps, not Foursquare, not FieldTrips...
感谢您大家。
推荐答案
我找到了正确的回答我的问题becouse @GuyS第二个职位的:
I found the correct answer to my question becouse of @GuyS second post:
添加在你AppDelegate.m applicationDidEnterBackground
Adding that in your AppDelegate.m applicationDidEnterBackground
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
// Synchronize the cleanup call on the main thread in case
// the task actually finishes at around the same time.
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
}];
}
}
和声明变量:
UIBackgroundTaskIdentifier bgTask;
之后,你只需要在applicationWillTerminate ...
After that you only have to stop your location services in applicationWillTerminate...
感谢您的答复。
这篇关于停止位置更新应用时终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!