Notifications for changes to Location Services?
I've been experimenting with CLLocationManager for an app I'm building. I understand how to check if Location Services are enabled and whether or not a user has allowed my app to use their current location.
If a user allows my app to use their location initially, and then the user either:
- turns location services off explicitly
- puts the phone in airplane mode
- explicitly de-authorizes my app to use their location
Are any notifications posted that I can subscribe to and respond to automatically when they reopen my app?
If not, would the best way to handle this scenario (so I can update views that were displaying GPS coordinates) to manually put this check in my AppDelegate's applicationDidFinishLaunching and applicationWillEnterForeground methods?
The reason I was thinking it should go there is because when you relaunch an app, viewWillAppear is not triggered for the first view, and if that view needs to change from showing GPS coordinates to a friendly message asking them to re-enable location services, the AppDelegates were the best hook I coul开发者_JAVA百科d think of.
Thanks!
On iOS 4.2 and later you will get a delegate call
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
Your approach is sound. If you find Core Location is unavailable on re-opening the app or network access has changed, you could then send a notification to those viewControllers that need to updated accordingly. Check out NSNotificationCenter
Even if you adopt the above I would suggest you do these check every time in viewDidAppear anyway as network access could be lost at anytime. Plus in line tests where you do any location checking.
精彩评论