stopMonitoringForRegion with dummy lat long但是右边的"标识符"

Ash*_*had 4 iphone objective-c cllocationmanager

我正在我的应用程序中安排和取消区域监控,如下所示.

- (void) setLocationReminderForLatitude:(double) latitude longitude:(double) longitude radiusInMetres:(double) radius withIdentifier:(NSString *) identifier
{
    CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(latitude, longitude) radius:radius identifier:identifier];
    [coreLocation startMonitoringForRegion:region desiredAccuracy:50]; //50 metres
}

- (void) cancelLocationNotification:(NSString *)identifier
{
    CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(0.0, 0.0) radius:100.0 identifier:identifer];
    [coreLocation stopMonitoringForRegion:region];
}
Run Code Online (Sandbox Code Playgroud)

在取消区域监控时,我可能不一定具有我最初用于开始监控该区域的中心和半径信息,但标识符是正确的.这会有用吗?

文档中没有提到任何相关内容.

Bil*_*ess 7

您需要拉出正确的区域以禁用监控.我要做的是遍历所有启用的区域,然后停止监视与您的标识符匹配的区域.

for (CLRegion *region in [locationController.locationManager monitoredRegions]) {
    if (region.identifier isEqual:yourIdentifier]) { // change this to match your identifier format
        [locationController.locationManager stopMonitoringForRegion:region];
    }
}
Run Code Online (Sandbox Code Playgroud)