CLLocationManager don't stop

好久不见. 提交于 2020-01-11 05:40:30

问题


Dear fellow developers,

I am trying hard to find a solution for my problem regarfing CLLocationManager.

I use a CLLocationManager instance in my Application. If the user selects the Home button on the device or terminates the application I want the location services to stop.

Therefor I call [self.locationManager stopUpdatingLocation]; - But this somehow doesn't work. The application enters the background and the small location arrow in the upper right corner of the status bar don't disappear. Even if I add [self.locationManager release] or self.locationManager.delegate = nil; - the location tracking don't stop :-/

It only disappears if I go to my device settings and switch off location services for the app. Whenever I switch back to location service enabled I immediately get a purple colored arrow next to the switch toggle and the icon reappears in the status bar.

My question is how can I turn off location services when the app enters the background or is terminated?

Thanks a lot in advance and have a nice day :-)


回答1:


You do it the right way. When entering background, it's ok if some delegate methods are called for some seconds. That should stop.

Where do you stop the location updates ? Are you sure it is triggered ? If yes, are your delegate method called even if the visual indicators tell something else ?

Are you sure you don't trigger a method that reactivate the location update after you have stopped it (because for example you can receive some updates even after stopped).




回答2:


Your location is disabled. The location service icon "meaning" has changed on iOS 5. Take a look at this question: https://apple.stackexchange.com/questions/27463/why-is-the-location-services-icon-always-present

I Quote the answer:

It's a new feature in ios 5 called "region Monitoring"

The reason it's active even if the app is closed is that this feature runs in iOS 5 core and notifies all apps that are registered when they have entered or left a specific geo-fence.

Reminders does that when you use a location based reminder.

Although the location icon appears at all time. This actually has very minimal impact on the battery due to apple really optimizing this feature by using cell and wifi mostly.

Your app is working ok. The system behaviour is the one who changed.




回答3:


For instance if you started monitoring a significant location change, then you should unsubscribe from it with the corresponding pair method. If you are using region enter, then until you unsubscribe, the system will notify your delegates.



来源:https://stackoverflow.com/questions/8155456/cllocationmanager-dont-stop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!