5

I am testing on an iPad 3rd gen on iOS 7.1 since I have no other iOS device for the moment.

The first time I run my app, it starts monitoring for several regions. The status bar and the Location Services settings page are showing the outlined location services icon (my app is the only one in the list that has the outlined icon). When I kill my app, the icon is still showing on both places since I do not stop monitoring the regions yet. Until then everything is fine.

My problem is when I run my app for a second time, I stop monitoring for all monitored regions, but the location services outlined icon does not disappear on the status bar and the Location Services settings page...

Here is my code called at the first run :

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

And my code called at the second run :

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

If I uninstall my app, the outlined location services icon disappear. But why is the icon not disappearing when I stop monitoring the monitored regions?


EDIT: After more testing, I found that the instance of the CLLocationManager that I have on the second run has no monitored regions ([self.locationManager monitoredRegions] returns nil)...


EDIT 2: I also found that if, on the second run, I start monitoring all the same regions that started monitoring on the first run AND THEN I stop monitoring them, the outlined location services icon disappear. Is this a normal behavior? I read nothing about that in all my internet researches...

Raphael Royer-Rivard
  • 2,252
  • 1
  • 30
  • 53

0 Answers0