I am seeing some unexpected behavior in my app when testing with locking screen locked.
The process flow is:
1) App receives a silent push notification
2) App requests location information via existing CLLocationManager startUpdatingLocation call
3) Upon receipt of a location update, API call is made with information
The flow works as expected when the app is in the foreground as well as the background.
When the device is locked (with or without a PIN enabled) upon receipt of the push notification, the startLocationUpdates method is called, but the callback didUpdateLocations is invoked only about 50% of the time.
Any information on the cause of this behavior is appreciated.
Basic Code Flow
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if(self.deviceLocationManager == nil)
{
NSLog(@"setUpLocation - Creating a LocationManager.");
self.deviceLocationManager = [[CLLocationManager alloc] init];
self.deviceLocationManager.delegate = self;
self.deviceLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.deviceLocationManager.distanceFilter = kCLDistanceFilterNone;
self.deviceLocationManager.pausesLocationUpdatesAutomatically = NO;
if ([self.deviceLocationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.deviceLocationManager requestAlwaysAuthorization];
}
if ([self.deviceLocationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
{
[self.deviceLocationManager setAllowsBackgroundLocationUpdates:YES];
}
}
else
{
self.deviceLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.deviceLocationManager.distanceFilter = kCLDistanceFilterNone;
self.deviceLocationManager.pausesLocationUpdatesAutomatically = NO;
}
[self.deviceLocationManager startUpdatingLocation];
completionHandler(UIBackgroundFetchResultNewData);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@":::: NEW LOCATION UPDATE RECEIVED ::::");
CLLocation *location = [locations lastObject];
CLLocationAccuracy horizontalAccuracy = location.horizontalAccuracy;
NSLog(@"::::appDelegate - NEW LOCATION UPDATE ACCURACY IS - %f",horizontalAccuracy);
//Make the API call here.......
}