【发布时间】:2014-09-28 17:07:53
【问题描述】:
有没有办法防止 CLLocationManager 在启动之间保持受监控的区域?每次启动应用程序时,我都需要添加一组新的受监控区域,而旧的不再有用。有没有办法阻止它们持续存在或在启动时清除所有旧的?
【问题讨论】:
标签: ios core-location geofencing clregion clcircleregion
有没有办法防止 CLLocationManager 在启动之间保持受监控的区域?每次启动应用程序时,我都需要添加一组新的受监控区域,而旧的不再有用。有没有办法阻止它们持续存在或在启动时清除所有旧的?
【问题讨论】:
标签: ios core-location geofencing clregion clcircleregion
当然可以清除当前监控的所有区域:
+(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)
}
【讨论】: