Question

I am using a NavigationController to display a list of geo-fences available to the user. At the top there is a global on/off switch that I would like to use to disable any fences registered with CoreLocation -startMonitoringForRegion.

My fences seem to be registering ok and working for the most part, but no matter how many times I disable the fences individually, I'm still getting the purple location arrow indicating that the system is still monitoring my location and/or fences.

When I disable my fences individually, this is how I'm doing it.

CLLocationCoordinate2D coord;
coord.latitude = [[settingsData valueForKey:@"latitude"] doubleValue];
coord.longitude = [[settingsData valueForKey:@"longitude"] doubleValue];
CLLocationDistance radius = [[settingsData valueForKey:@"radius"] intValue];
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:radius identifier:[settingsData valueForKey:@"name"]];

// remove this fence from system monitoring
[locationManager stopMonitoringForRegion:region];
[region release];

I've gone through all of Apple's documentation on CoreLocation and use of these methods and I'm at the end of my rope.

I've tried calling [locationManager monitoredRegions]; but it only returns the active fence and only when I have my detail view loaded up. I'm not able to call it any other place in my program and get it to return any of my fences, even though I know they should be active. If anyone has any advice where to go next, I'm all ears.

Was it helpful?

Solution

Or, a more simple solution:

for (CLRegion *monitored in [locationManager monitoredRegions])
    [locationManager stopMonitoringForRegion:monitored];

OTHER TIPS

Ok, I think I can answer my own question here finally. Does this mean I can claim my own bounty? :D

First off, the lingering location arrow seems to be an iOS bug. I have found multiple stories out there with the very same issue. So there won't be much I can do about that for now.

As far as removing all of my regions at once, I got this down pat now.

NSArray *regionArray = [[locationManager monitoredRegions] allObjects]; // the all objects is the key
for (int i = 0; i < [regionArray count]; i++) { // loop through array of regions turning them off
     [locationManager stopMonitoringForRegion:[regionArray objectAtIndex:i]];
}

I was able to display my array and proved they were all in there. Another check after removing shows they are all gone. Whew!! The issue of the location arrow remains depending on which version of iOS you are running. I can't that I guess. If you have users, make sure you inform them the purple arrow is not your fault. For more info on the issue, you can start here. GetSatisfaction Good luck.

Yes it is an iOS bug. Deleting and reinstalling the app does not help. The only way I managed to get rid of the problem is by resetting location warnings

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top