在屏幕锁定测试时,我在iOS应用中看到了一些意外行为。
流程是:
1)应用程序通过content-available标志
接收静默推送通知2)App通过现有的CLLocationManager startUpdatingLocation调用
请求位置信息3)收到位置更新后,将使用信息进行API调用
当应用在前台以及应用在后台时,流程会按预期工作。
如果我在收到推送通知时使用屏幕锁定按钮(启用或不启用PIN)锁定设备,则会调用startLocationUpdates方法,但仅在大约50%的时间内收到回调didUpdateLocations。
感谢有关此行为原因的任何信息。
基本代码流
-(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.......
}