[英]Can you stop regions from persisting between launches with CLLocationManager?
Is there a way to prevent CLLocationManager from persisting monitored regions between launches? 有没有一种方法可以防止CLLocationManager在两次启动之间保留受监视的区域? 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? 有没有办法防止它们持久存在或在启动时清除所有旧的?
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. 我已经从共享管理器类中复制了它们。
In SWIFT 4 you can stop all the regions from being monitored like 在SWIFT 4中,您可以像这样停止监视所有区域
let monitoredRegions = locationManager.monitoredRegions
for region in monitoredRegions{
locationManager.stopMonitoring(for: region)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.