简体   繁体   English

如何关闭位置服务?

[英]How to turn off location services?

If a user has location services on, I assign my RootController as its delegate: 如果用户启用了位置服务,我将我的RootController指定为其委托:

appDelegate.clLocationManager.delegate = self;

where appDelegate is an instance of my application delegate, which is where I have the location services instance. 其中appDelegate是我的应用程序委托的实例,这是我有位置服务实例的地方。 clLocationManager is an instance of CLLocationManager. clLocationManager是CLLocationManager的一个实例。 If I discover the user is outside of a certain region, I want to disable location service delegates. 如果我发现用户不在某个区域,我想禁用位置服务代表。 I do this: 我这样做:

appDelegate.clLocationManager.delegate = nil;

But this method still fires: 但是这种方法仍然会引发:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

Is there another way to disable location services or at least keep its methods from firing? 是否有另一种方法来禁用位置服务或至少保持其方法不被触发?

Yes, you need to tell it to stop updating location: 是的,您需要告诉它停止更新位置:

[appDelegate.clLocationManager stopUpdatingLocation];

After that you can also release it. 之后你也可以发布它。

See the documentation for details. 有关详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM