有没有办法阻止CLLocationManager在启动之间保持受监控的区域?每次启动应用程序时,我都需要添加一组新的受监控区域,而旧区域则不再有用。有没有办法阻止他们在发布时坚持或清除所有旧的?
当然,您可以清除当前监控的所有区域:
+(void)clearRegionWatch
{
for(CLRegion *region in [[WGLocation shared].locationManager monitoredRegions]){
[[WGLocation shared].locationManager stopMonitoringForRegion:region];
}
}
如果您有要删除的特定标识符:
+(void)clearRegionWatchForKey:(NSString *)key
{
for(CLRegion *region in [[WGLocation shared].locationManager monitoredRegions]){
if([region.identifier isEqualToString:key]){
[[WGLocation shared].locationManager stopMonitoringForRegion:region];
}
}
}
您可以将函数的内部复制到应用程序中的适当位置。我已经从我的共享管理器类中复制了它们。
在SWIFT 4中,您可以阻止所有区域受到监控
let monitoredRegions = locationManager.monitoredRegions
for region in monitoredRegions{
locationManager.stopMonitoring(for: region)
}