iOS 后台获取运行时间过长?

标签 ios background-fetch

我有一个每 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/

相关文章:

iphone - 即使我的内容大小小于其框架,我的 ScrollView 也会滚动

iOS swift : AWS SDK - downloading file from S3 - get contents without saving file

ios - 延迟在后台获取 EXC_BAD_ACCESS

ios - 如果应用程序不在前台,DownloadTask 在作为后台获取的一部分执行时会暂停吗?

ios - UITextView sizeToFit 不工作

ios - 将数组元素与预定义值进行比较时出错?

ios - iOS Background fetch 是否仅在后台模式下触发?

iOS:如何在 Storyboard中实际没有单元格的情况下将可重用的 'default' 单元格出列

Flutter WorkManager 后台获取带有 StateFull 小部件的示例