Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you stop regions from persisting between launches with CLLocationManager?

Is there a way to prevent CLLocationManager from persisting monitored regions between launches? Every time the app is launched I need to add a new set of monitored regions and the old ones are no longer useful. Is there a way to either prevent them from persisting or clear all of the old ones at launch time?

like image 517
charleyh Avatar asked Aug 05 '14 21:08

charleyh


1 Answers

Of course you can clear all the regions currently monitored:

+(void)clearRegionWatch
{
    for(CLRegion *region in [[WGLocation shared].locationManager monitoredRegions]){
        [[WGLocation shared].locationManager stopMonitoringForRegion:region];
    }
}

If you had a specific identifier that you wanted to remove:

+(void)clearRegionWatchForKey:(NSString *)key
{
    for(CLRegion *region in [[WGLocation shared].locationManager monitoredRegions]){
        if([region.identifier isEqualToString:key]){
            [[WGLocation shared].locationManager stopMonitoringForRegion:region];
        }
    }
}

You can copy the internals of the function into an appropriate place in your application. I've copied them from my shared manager class.

like image 73
William George Avatar answered Sep 19 '22 16:09

William George