ios - 如何停止在我的 iOS 应用程序中使用定位服务?

标签 ios service cllocationmanager ibeacon

我有一个 iOS 应用程序,它使用 CLLocationManager 来监控区域并获取 GPS 更新。大多数时候,我希望我的应用程序在手机进入后台甚至被杀死时继续跟踪手机,并且它运行良好(在我的应用程序被杀死后我仍然可以在状态栏中看到小箭头)。问题是,在位置服务重新启动我的应用程序后,我无法停止监视区域和 GPS 更新。

当位置服务重新启动我的应用时,我会实例化 CLLocationManager,然后在设置其委托(delegate)之前调用其方法 stopRangingBeaconsInRegionstopUpdatingLocationnil 及其本身到 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/

相关文章:

ios - EXIF 的 PHContentEditingInputRequestOptions block 主线程

ios - 为什么我无法将子 Pane plist 文件粘贴到 Xcode 4.3.3 中项目的 Settings.bundle 文件夹中?

grails:维护从服务到 Controller 的事务上下文

android - 绑定(bind)到android中的同一个服务实例

ios - 扩展 MKPolylines 或创建多个 MKPolylines?

ios - 如何区分调用 didEnterRegion 的 CLCircularRegion 和 CLBeaconRegion

swift - 调用 requestWhenInUseAuthorization 获取位置权限时出错

ios - 将 NSMutableArray 设置为 NSDictionary - Objective C

ios - 有没有一种方法可以在 sttwitter 中获取大量推文?

java - ServerSocket,Tomcat 作为服务和端口