你能用CLLocationManager阻止区域在启动之间保持不变吗?

cha*_*eyh 5 core-location ios geofencing clregion clcircleregion

有没有办法阻止CLLocationManager在启动之间保持受监控的区域?每次启动应用程序时,我都需要添加一组新的受监控区域,而旧区域则不再有用.有没有办法阻止他们在发布时坚持或清除所有旧的?

Wil*_*rge 5

当然,您可以清除当前监控的所有区域:

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

如果您有要删除的特定标识符:

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

您可以将函数的内部复制到应用程序中的适当位置.我已经从我的共享管理器类中复制了它们.