首页 > 解决方案 > 如何解决这些 CloudKit 后台任务警告

问题描述

我有一个正常运行的 iOS 应用程序,它产生了一些令人不安的警告消息,我想解决它们。

从控制台:

Background Task 37 ("CoreData: CloudKit Import"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

但是,此警告会定期重复,每次使用不同的任务 ID。我想如果我可以捕获任务 ID,我可以确定在哪里调用

UIApplication.endBackgroundTask(_:)

我不知道是否可以获取任务 ID。我确实设置了一个通知观察器来检查数据更改。我不想删除它。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    
    OperationQueue.main.addOperation({ () -> Void in
        self.fetchProjects()
    })
}

标签: iosswiftcloudkit

解决方案


推荐阅读