我有一个每 7 小时运行一次的后台作业,它进行一次 API 调用大约需要 1-3 秒。查看设置的电池部分,显示作业在过去 20 小时内在后台运行了 40 分钟。
模拟后台抓取工作正常,并在几秒钟内调用完成。
知道为什么它运行时间太长了吗?
NSTimeInterval backgroundFetchTimeInterval = 7 * 3600;
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:backgroundFetchTimeInterval];
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[SyncManager sharedManager] performSyncWithCompletion:^(NSArray *results, NSError *error) {
if (error) {
completionHandler(UIBackgroundFetchResultFailed);
}
else {
if (resultCount > 0) {
completionHandler(UIBackgroundFetchResultNewData);
}
else {
completionHandler(UIBackgroundFetchResultNoData);
}
}
}];
}
最佳答案
你可以做的是在一个文件中写下你花了多少时间。
想法是在文件中写下开始后台获取的时间和完成后台获取的时间..这样你就可以计算出你真正花了多少钱,这将有助于你更好地分析。
关于iOS 后台获取运行时间过长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120385/