-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
使用content-available = 1
调用它。下载任务启动(显示NSLogs
),但不完成被调用的任务。只有在将应用程序切换回Foreground时,才能完成之前调用的任务。
任何想法......这怎么会发生?
答案 0 :(得分:0)
你必须使用UIBackgroundTaskIdentifier.to在后台执行api调用。
- (void)applicationDidEnterBackground:(UIApplication *)application {
isnotificationScreenopen = NO;
UIBackgroundTaskIdentifier bgTaskId =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTaskId];
NSLog(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining);
}];
NSLog(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining);
}
您也可以阅读此链接
objective c - Proper use of beginBackgroundTaskWithExpirationHandler