4

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

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

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

该文档没有提到任何关于此的内容。

4

1 回答 1

7

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

for (CLRegion *region in [locationController.locationManager monitoredRegions]) {
    if (region.identifier isEqual:yourIdentifier]) { // change this to match your identifier format
        [locationController.locationManager stopMonitoringForRegion:region];
    }
}
于 2012-07-09T18:34:54.243 回答