地理围栏委托方法、didExitRegion、和适用于所有应用程序状态(前台/背景/挂起和终止状态)。一旦任何区域被传递,应用程序需要同步地命中3个相互依赖的apis。在前景状态下,所有操作都很好,但没有处于挂起/终止状态。不知道这次失败的确切原因。
在这种情况下,一个原因可能是限制清醒时间来执行所有任务(死亡/暂停状态)。我试过beginBackgroundTaskWithExpirationHandler,但这帮不了我。
- (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];
}如果有人对我做错了什么有任何建议,请帮忙。提前感谢
发布于 2017-03-17 10:37:22
我自己发布这个答案,只是为了澄清上面的代码对于这样的任务来说已经足够了。使用上面的代码,所有需要的任务都在所有应用程序状态下工作-- (foreground/background/killed/suspended).。
我的问题是核心数据的实现。一旦食谱对象为零,我就跳过了进一步的代码。它让我觉得API没有启动,因为在死亡状态限制的时间限制。
希望上面的代码能帮助其他人解决同样的问题。
https://stackoverflow.com/questions/42808248
复制相似问题