Rap*_*ard 5 cllocationmanager ios location-services
由于目前没有其他iOS设备,因此我正在iOS 7.1的iPad第三代上进行测试。
第一次运行我的应用程序时,它将开始监视多个区域。状态栏和“位置服务”设置页面上显示了概述的位置服务图标(我的应用程序是列表中唯一带有概述图标的应用程序)。当我终止我的应用程序时,该图标仍然在两个地方都显示,因为我还没有停止监视区域。在那之前,一切都很好。
我的问题是当我第二次运行我的应用程序时,我停止监视所有受监视的区域,但是状态栏和“位置服务设置”页面上的“位置服务概述”图标没有消失...
这是我在第一次运行时调用的代码:
- (void) getLocationManagerInstance {
if (!self.locationManager) {
self.locationManager = [CLLocationManager new];
}
self.locationManager.delegate = self;
}
- (void) startLocationGathering {
if(self.shouldUpdateGPSLocations) {
[self.locationManager startMonitoringSignificantLocationChanges];
}
}
- (void) startMonitoringBeaconRegions {
if(self.rootRegion) {
[self.locationManager startMonitoringForRegion:self.rootRegion];
}
if (self.beaconRegions && self.beaconRegions.count < 20) {
[self.beaconRegions enumerateObjectsUsingBlock:^(CLBeaconRegion* region, NSUInteger idx, BOOL *stop) {
[self.locationManager startMonitoringForRegion:region];
}];
}
}
- (void) startMonitoringCircularRegions {
if (self.gpsRegions && self.gpsRegions.count) {
[self.gpsRegions enumerateObjectsUsingBlock:^(CLCircularRegion* region, NSUInteger idx, BOOL *stop) {
[self.locationManager startMonitoringForRegion:region];
}];
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码在第二次运行时调用:
- (void) getLocationManagerInstance {
if (!self.locationManager) {
self.locationManager = [CLLocationManager new];
}
self.locationManager.delegate = self;
}
- (void) locationManagerCleanup {
[AWRUtils dlog:@"locationManagerCleanup"];
NSArray* monitoredRegions = [self.locationManager monitoredRegions].allObjects;
for (CLRegion* r in monitoredRegions) {
[self.locationManager stopMonitoringForRegion:r];
}
NSArray* rangedRegions = [self.locationManager rangedRegions].allObjects;
for (CLBeaconRegion* r in rangedRegions) {
[self.locationManager stopRangingBeaconsInRegion:r];
}
[self.locationManager stopUpdatingLocation];
[self.locationManager stopMonitoringSignificantLocationChanges];
}
Run Code Online (Sandbox Code Playgroud)
如果我卸载应用程序,则概述的位置服务图标会消失。但是,当我停止监视受监视区域时,为什么图标没有消失?
编辑:经过更多测试,我发现我第二次运行的CLLocationManager实例没有受监视的区域([self.locationManager monitoredRegions]返回nil)...
编辑2:我还发现,如果在第二次运行中开始监视与第一次运行中开始监视的所有相同区域,然后停止监视它们,则概述的位置服务图标将消失。这是正常现象吗?在我所有的互联网研究中,我对此一无所知...
| 归档时间: |
|
| 查看次数: |
242 次 |
| 最近记录: |