24

我正在使用 NavigationController 来显示用户可用的地理围栏列表。在顶部有一个全局开/关开关,我想用它来禁用使用 CoreLocation -startMonitoringForRegion 注册的任何栅栏。

我的围栏似乎注册正常并且大部分时间都在工作,但无论我单独禁用围栏多少次,我仍然收到紫色位置箭头,表示系统仍在监控我的位置和/或围栏。

当我单独禁用我的栅栏时,我就是这样做的。

CLLocationCoordinate2D coord;
coord.latitude = [[settingsData valueForKey:@"latitude"] doubleValue];
coord.longitude = [[settingsData valueForKey:@"longitude"] doubleValue];
CLLocationDistance radius = [[settingsData valueForKey:@"radius"] intValue];
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:radius identifier:[settingsData valueForKey:@"name"]];

// remove this fence from system monitoring
[locationManager stopMonitoringForRegion:region];
[region release];

我已经阅读了 Apple 关于 CoreLocation 的所有文档以及这些方法的使用,但我已经走到了尽头。

我试过打电话[locationManager monitoredRegions];,但它只返回活动围栏,只有当我加载了我的详细视图时。我无法在程序中的任何其他地方调用它并让它返回我的任何栅栏,即使我知道它们应该处于活动状态。如果有人对下一步去哪里有任何建议,我会全力以赴。

4

3 回答 3

51

或者,更简单的解决方案:

for (CLRegion *monitored in [locationManager monitoredRegions])
    [locationManager stopMonitoringForRegion:monitored];
于 2012-07-03T01:49:08.120 回答
13

好的,我想我终于可以在这里回答我自己的问题了。这是否意味着我可以索取自己的赏金?:D

首先,挥之不去的位置箭头似乎是一个 iOS 错误。我在同一个问题上发现了多个故事。所以我现在对此无能为力。

至于一次删除我所有的区域,我现在已经成功了。

NSArray *regionArray = [[locationManager monitoredRegions] allObjects]; // the all objects is the key
for (int i = 0; i < [regionArray count]; i++) { // loop through array of regions turning them off
     [locationManager stopMonitoringForRegion:[regionArray objectAtIndex:i]];
}

我能够展示我的阵列并证明它们都在里面。删除后的另一次检查显示它们都消失了。呼!!位置箭头的问题仍然存在,具体取决于您运行的 iOS 版本。我猜不出来。如果您有用户,请确保告知他们紫色箭头不是您的错。有关该问题的更多信息,您可以从这里开始。GetSatisfaction祝你好运。

于 2011-08-25T21:07:26.993 回答
3

是的,这是一个 iOS 错误。删除并重新安装应用程序没有帮助。我设法摆脱问题的唯一方法是重置位置警告

于 2011-08-26T02:17:37.533 回答