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

CloudKit operations execute in development version but sometimes hang in production version

我在我的应用程序中以两种不同的方式调用 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.

中设置为 'lower' 标准值

qualityOfService 的文档说明:

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.