如何禁用使用-startMonitoringForRegion注册的任何CLRegion对象? [英] How can I disable any CLRegion objects registered with -startMonitoringForRegion?

查看:415
本文介绍了如何禁用使用-startMonitoringForRegion注册的任何CLRegion对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a NavigationController to display a list of geo-fences available to the user. At the top there is a global on/off switch that I would like to use to disable any fences registered with CoreLocation -startMonitoringForRegion.

我的栅栏似乎正在注册正常在大多数情况下工作,但无论我多少次单独禁用围栏,我仍然会得到紫色位置箭头,表示系统仍在监视我的位置和/或围栏。

My fences seem to be registering ok and working for the most part, but no matter how many times I disable the fences individually, I'm still getting the purple location arrow indicating that the system is still monitoring my location and/or fences.

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

When I disable my fences individually, this is how I'm doing it.

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

我已经浏览了所有关于CoreLocation的Apple文档并使用了这些方法而且我在我的绳索结束了。

I've gone through all of Apple's documentation on CoreLocation and use of these methods and I'm at the end of my rope.

我试过调用 [locationManager monitoredRegions]; 但它只返回活动围栏,只有当我有我的详细信息视图已加载。我无法在程序中的任何其他位置调用它并让它返回我的任何围栏,即使我知道它们应该是活动的。如果有人有任何建议,接下来我会全力以赴。

I've tried calling [locationManager monitoredRegions]; but it only returns the active fence and only when I have my detail view loaded up. I'm not able to call it any other place in my program and get it to return any of my fences, even though I know they should be active. If anyone has any advice where to go next, I'm all ears.

推荐答案

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

Or, a more simple solution:

for (CLRegion *monitored in [locationManager monitoredRegions])
    [locationManager stopMonitoringForRegion:monitored];

这篇关于如何禁用使用-startMonitoringForRegion注册的任何CLRegion对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆