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

问题描述 投票:5回答:2

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

ios core-location geofencing clregion clcircleregion
2个回答
5
投票

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

+(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];
        }
    }
}

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


0
投票

在SWIFT 4中,您可以阻止所有区域受到监控

let monitoredRegions = locationManager.monitoredRegions

for region in monitoredRegions{
    locationManager.stopMonitoring(for: region)
}
© www.soinside.com 2019 - 2024. All rights reserved.