nsoperation - CloudKit 操作在开发版本中执行,但有时在生产版本中挂起

标签 nsoperation nsoperationqueue cloudkit cloudkit-environments

我在应用程序中以两种不同的方式调用 iCloud 数据库:

1. 调用 CKDatabase 便捷方法在开发(模拟器)和生产(设备)环境中完美运行:

let privateDatabase = CKContainer.defaultContainer().privateCloudDatabase

privateDatabase.fetchRecordWithID(recordID, completionHandler: { (record, error) -> Void in
    // handle record and errors
})

2. 将 CKOperations 添加到主队列在开发环境中工作得很好,并且当我在生产环境中测试时工作了一段时间 - 但随后任意地,经过几个小时的间歇性测试,对数据库的调用刚刚开始挂起 - 不会产生错误,也不会执行完成代码。 (fetchRecordWithID 调用仍然始终完美运行。)

let op1 = CKModifyRecordsOperation(recordsToSave: records, recordIDsToDelete: nil)
op1.modifyRecordsCompletionBlock = { (savedRecords, deletedRecordIDs, error) -> Void in
    // handle records and errors
    }
op1.database = privateDatabase

// let op2, op3...

NSOperationQueue.mainQueue().addOperations([
    op1,
    op2,
    op3,
    ], waitUntilFinished: false)

在 CloudKit 仪表板的“使用情况”面板中,没有任何东西远远接近限制。我没有考虑哪些其他变量 - 或者我可以运行哪些其他测试来找出问题所在?

最佳答案

尝试设置 op1、op2 和 op3.qualityOfService = .UserInitiated

该设置已在 iOS 9 中设置为“较低”标准值。

文档说明了服务质量:

The relative amount of importance for granting system resources to the operation. Service levels affect the priority with which an operation object is given access to system resources such as CPU time, network resources, disk resources, and so on. Operations with a higher quality of service level are given greater priority over system resources so that they may perform their task more quickly. You use service levels to ensure that operations responding to explicit user requests are given priority over less critical work. This property reflects the minimum service level needed to execute the operation effectively. The default value of this property is NSOperationQualityOfServiceBackground and you should leave that value in place whenever possible. When changing the service level, use the minimum level that is appropriate for executing the corresponding task. For example, if the user initiates a task and is waiting for it to finish, assign the value NSOperationQualityOfServiceUserInitiated to this property. The system may give the operation a higher service level to the operation if the resources are available to do so.

关于nsoperation - CloudKit 操作在开发版本中执行,但有时在生产版本中挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33336796/

相关文章:

ios - NSOperation 与 Grand Central Dispatch

iphone - 如何在与操作相同的线程中取消 NSOperation?

ios - 调度组通知似乎被调用得太早

iphone - NSOperationQueue阻止了不相关的NSOperationQueue?

objective-c - iOS 对上传任务进行排队

ios - 如何通过 Today Extension (iOS 8) 访问 Core Data/CloudKit

objective-c - NSOperationQueue 有储备能力吗?

swift - 在串行队列上运行异步任务时,有没有一种方法我们可能会面临竞争条件

ios - CloudKit 推送通知 didReceiveRemoteNotification 从未调用过

ios - 如何定义 CKRecord 类