Geo-Fencing delegate methods didExitRegion and didEnterRegion working for all application states (Foreground / Background / Suspended and Killed state). Once any region gets passed, application need to hit 3 mutually dependent apis synchronously. All is working fine in foreground state, but not in Suspended / Killed state. Don’t know the exact reason of this fail.
One reason may be restricted awake time limit to perform all tasks in such case (killed/ suspended state). I tried beginBackgroundTaskWithExpirationHandler , but its not helping me out.
- (void) beginBackgroundUpdateTask{
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[self endBackgroundUpdateTask];
}];
}
- (void) endBackgroundUpdateTask{
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
_backgroundTask = UIBackgroundTaskInvalid;
}
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(nonnull CLRegion *)region
{
[kSharedAppDelegate beginBackgroundUpdateTask];
NSString *locId = [region.identifier substringFromIndex:1];
Recipe *recipe = [Recipe getSelectedReturnRecipeForLocationId:locId];
if(recipe)
{
[self callAPIOne:^(NSDictionary *dictResponse) {
[self callAPITwo:params forAbc:NO];
} withFailed:^(NSDictionary *dictResponse) {
[kSharedAppDelegate endBackgroundUpdateTask];
} showLoader:NO];
}
else
[kSharedAppDelegate endBackgroundUpdateTask];
}
Please help, if anyone has any advice about what I am doing wrong here. Thanks in advance