-->

Core Location Best Placement and User Interruption

2019-08-24 05:40发布

问题:

My application uses Core Location in three different views. It's working perfectly. In my first view, I subclass the CLLocationManager and use protocol methods for location updates to my calling class. Before I install the framework and code in my other classes, I was wondering:

Is the protocol method the best way?

What happens to the Core Location execution if the user exits the view or quits the app while it's trying to get a location fix? Is the location task terminated with the GPS system turned off immediately?

If the user simply switches to another view, is it OK to assume that I can start Core Location in the next view without regard to the last?

Where should the first update location call be placed. Should the application delegate instantiate the CLLocation Manager class using protocol so that it can update any of the views chosen or should each class instantiate the manager.

Any feedback would be appreciated.

Thanks.

回答1:

Since you don't really need more than one CLLocationManager, you could try creating it as an property of your application’s delegate. Then, when you load your views, in the -viewWillAppear:animated: method of your view controller, include a [locationManager setDelegate:self]; line and it will start sending delegate messages to the currently-visible view controller.