Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

iphone - How can I disable any CLRegion objects registered with -startMonitoringForRegion?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Or, a more simple solution:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...