我有一个 iOS 应用程序,它使用 CLLocationManager
来监控区域并获取 GPS 更新。大多数时候,我希望我的应用程序在手机进入后台甚至被杀死时继续跟踪手机,并且它运行良好(在我的应用程序被杀死后我仍然可以在状态栏中看到小箭头)。问题是,在位置服务重新启动我的应用程序后,我无法停止监视区域和 GPS 更新。
当位置服务重新启动我的应用时,我会实例化 CLLocationManager
,然后在设置其委托(delegate)之前调用其方法 stopRangingBeaconsInRegion
和 stopUpdatingLocation
到 nil
及其本身到 nil
。
感谢 NSLogger,我可以看到我的回调不再被调用,但状态栏中的小箭头保留在那里(并且我的应用程序是我允许从设置菜单使用位置服务的唯一应用程序)。
我错过了什么?有没有办法知道我的应用程序中哪些内容仍在使用定位服务?
最佳答案
当您调用 stopRangingBeaconsInRegion 时,您从哪里获取区域列表?正确的方法如下:
for (CLRegion *monitored in [self.locationManager monitoredRegions]) {
NSLog(@"Stopping monitoring on: %@", monitored.identifier);
[self.monitoringLocationManager stopMonitoringForRegion:monitored];
}
for (CLBeaconRegion *region in [self.locationManager rangedRegions]) {
NSLog(@"Stopping ranging on: %@ ", region.identifier);
[self.rangingLocationManager stopRangingBeaconsInRegion:region];
}
关于ios - 如何停止在我的 iOS 应用程序中使用定位服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23526067/