SignificantLocationChanges not working with iOS 8
I have a problem since SignificantLocationChanges
the release of iOS 8. Method
[locationManager startMonitoringSignificantLocationChanges];
is called correctly after checking for accessibility, delegates work well too (I check it with a method didChangeAuthorizationStatus
that is part of the same delegate and object) and the compiler has no doubts, but absolutely no updates and no errors from the method didFailWithError
. The log says authorizationStatus is 4, which I think is ok.
Before iOS 8, everything works fine.
The first test device (iPad 2 with 3G) runs iOS 7.1.2 the second (iPhone 5) 8.0.2, when I use the normal method startUpdatingLocation
, I get updates right away. But it SignificantLocationChanges
will be much better for my job. Does anyone know where the error might be?
source to share
In iOS 8, you must request an "Always" authorization for your app to use significant locations.
Add a new line to the -Info.plist file with the NSLocationAlwaysUsageDescription key
Then ask for authorization if not already requested.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status == kCLAuthorizationStatusNotDetermined && [manager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[manager requestAlwaysAuthorization];
}
}
source to share
I have problems with startMonitoringSignificantLocationChanges
too ..
I added [self.locationManager requestWhenInUseAuthorization];
and added a line NSLocationWhenInUseUsageDescription
to the plist file.
When I run my application everything works, the delegate method gets didChangeAuthorizationStatus
called, but doesn't work with the delegate methods didUpdateLocation
or didFailWithError
.
But when I switch to startUpdatingLocation
, it magically works! But I need startMonitoringSignificantLocationChanges
to work because I don't want my app to consume battery for an event I don't need!
UPDATE !! Problem solved!
Oh, I understand why it is not working now !. The new SDK link here, this link says:
"You must call this method or the requestAlwaysAuthorization method before using location services. If a user grants when-in-use authorization to your application, your application can run most (but not all) location services while it is in the foreground. (Apps cannot use services that automatically restart the app, such as region monitoring or significant location change service.)
Thus, it cannot be used startMonitoringSignificantLocationChanges
with the method [self.locationManager requestWhenInUseAuthorization];
. Instead, you should use requestAlwaysAuthorization
!
source to share
Do you remember that you are calling the method
-requestAlwaysAuthorization
(or -requestWhenInUseAuthorization)
in your CLLocationManager? This is a new method in iOS 8 and it had to call it before starting location updates.
Also, double check if you are assigned and called -startUpdatingLocation
on the main thread. I'm not sure about this, but I think that calling it on a different thread might cause problems.
source to share