ios - 应用程序终止时停止位置更新

标签 ios background gps location terminate

我正在开发一个应用程序,当您位于促销地点附近时,该应用程序会发送通知。 我的问题是,当我进入后台然后退出应用程序时,我不希望位置服务在应用程序无法工作时工作(但我希望它们在后台工作)。

我只看到 3 个应用程序在关闭应用程序时会关闭 GPS,我想知道他们是如何做到这一点的,Facebook、Google map 和 Apple map ,而不是 Foursquare,不是 FieldTrips...

谢谢大家。

最佳答案

您可以为UIApplicationWillTerminateNotification添加一个观察者,您可以在其中启动locationManager并停止位置更新

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillTerminate:)
                                                 name:UIApplicationWillTerminateNotification
                                               object:nil];

收到通知时执行的方法

- (void)applicationWillTerminate:(NSNotification *)notification {
//stop location updates
}

关于ios - 应用程序终止时停止位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24778492/

相关文章:

ios - SKScene识别GameScene的高分

ios - 为 iOS 构建后 Ionic 应用程序链接器错误

html - 部分png文件的背景图像

Node.js GPS 设备跟踪性能注意事项

c# - 从 GPS 读取 NMEA 语句

android - Android中如何判断设备是否处于同一位置或者移动?

ios - 通过覆盖视频来保护 iOS 应用程序的内容

ios - 使用 Socket.io swift 客户端向 Sails 服务器发送虚拟 POST 请求

css - 嵌套的 div 被圆形容器 div 屏蔽掉

html - 更改 Bootstrap 进度条背景(不是进度条,而是进度条背景)