5

我正在 iOS 7.1 上的第三代 iPad 上进行测试,因为目前我没有其他 iOS 设备。

我第一次运行我的应用程序时,它开始监视几个区域。状态栏和定位服务设置页面显示了定位服务图标(我的应用程序是列表中唯一具有轮廓图标的应用程序)。当我杀死我的应用程序时,图标仍然显示在两个地方,因为我还没有停止监视这些区域。在那之前一切都很好。

我的问题是当我第二次运行我的应用程序时,我停止监视所有受监视的区域,但是位置服务概述的图标在状态栏和位置服务设置页面上没有消失...

这是我在第一次运行时调用的代码:

- (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];
        }];
    }
}

我的代码在第二次运行时调用:

- (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];
}

如果我卸载我的应用程序,概述的位置服务图标就会消失。但是为什么我停止监控监控区域时图标没有消失?


编辑:经过更多测试,我发现我在第二次运行时拥有的 CLLocationManager 实例没有受监控区域([self.locationManager monitoredRegions]返回nil)......


编辑 2:我还发现,如果在第二次运行时,我开始监视在第一次运行时开始监视的所有相同区域,然后我停止监视它们,概述的位置服务图标就会消失。这是正常行为吗?我在所有的互联网研究中都没有读到这方面的内容......

4

0 回答 0