I'm trying to use significant change location monitoring in iOS 8, but the didUpdateLocations method is never called. Here is the code for setting up the location manager:
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringSignificantLocationChanges];
}
Despite calling requestWhenInUseAuthorization
, nothing pops up to ask the user to authorize it. I have set NSLocationWhenInUseUsageDescription, and it still does not work. didChangeAuthorizationStatus
and didFailWithError
are also never called.
EDIT: I was able to get it to ask the user to allow location services, but even if you click allow it never shows the location.
into .plist file add
All the steps look complete but run :startUpdatingLocation only after you check for :didChangeAuthorizationStatus.
At this point, please make sure that the authorizationStatus is not kCLAuthorizationStatusNotDetermined or kCLAuthorizationStatusDenied.
If it is either, check for the string entries in info.plist.
If you feel all of it is correct, Make sure that you uninstall the app from the device. Perform a clean build and then run the app on the device.
The probable reason, why the authorization dialog is not shown with the OPs code, is that the location manager has to hang around for it to work.
Use a property or a static variable to keep
locationManager
in memory.There is currently a bug in iOS8 beta5 which always deactivate geolocation service for your app (at least for mine).
Go in
settings > Privacy > Location services > Your app > Always
.But I don't know why, but even if you set it to
Always
this setting will auto-deactivate, so please be patient and often return in the settings to configure again your app location.Maybe its because of the WhenInUseAuthorization is not enough for the "Significant Location Change" updates.
When i use AlwaysAuthorization, it just works.
i cannot find it in the docs. But you can check http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/. Under "Authorization Types" heading, it states that significant location updates need AlwaysAuthorization.
Try declare
CLLocationManager *locationManager
in your header file then it works. Unless I have declare it as a global variable it does not ask for permission and update location..h
.m
Delegate methods
info.plis