问题描述
我正在尝试从sharedDatabase中的自定义区域中获取CloudKit记录.
I am trying to fetch CloudKit records from a custom Zone in a sharedDatabase.
在共享过程中已正确创建区域.因此,我假定该区域正确是一个共享的自定义区域(它确实在我的CloudKit用户仪表板上,显示在默认容器的sharedDatabase下).
The zone has been created correctly during the share process. So I assume that the zone is correctly a shared custom zone (it is indeed in my CloudKit user dashboard, appearing under the sharedDatabase of the default container).
即使使用这段简单的代码来检索记录:
Even with this simple piece of code to retrieve records:
func loadRecords() {
let database = CKContainer.default().sharedCloudDatabase
let query = CKQuery(recordType: "Items", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
let operation = CKQueryOperation(query: query)
let zone = CKRecordZone(zoneName: "MyCustomZone")
var fetchedRecords: [CKRecord] = []
database.perform(query, inZoneWith: zone.zoneID) { (records, error) in
if let error = error {
print(error)
}
else if let records = records, let firstRecord = records.first {
print(firstRecord)
}
}
}
我一直收到此错误:(对不起,上一篇文章中缺少!)
I keep receiving this error: (sorry was missing in previous post!)
<CKError 0x280950840: "Invalid Arguments" (12/1009); "Only shared zones can be accessed in the shared DB">
对我所缺少的东西有什么想法吗?谢谢!
Any idea about what I am missing? Thank you!
推荐答案
对,我终于明白了.感谢此处有关StackOverflow的其他帖子: CloudKit共享
Right, I finally figured it out. Thanks to this additional post here on StackOverflow: CloudKit Sharing
您确实必须获取您的自定义区域.但是仅仅给它一个诸如"MyCustomZone"之类的名称是不够的,因为在您的共享数据库中,它变成了MyCustomZone:_acBxxxyyyzzz.CloudKit添加的后缀.
You indeed have to fetch your custom zone. But it is not enough to give it a name such as "MyCustomZone" because in your shared DB, it becomes MyCustomZone: _acBxxxyyyzzz. A suffix added by CloudKit.
如果您未获取所有共享区域,则永远不会有需要从中提取记录的正确的自定义区域.
If you don't fetch all your shared zones, you never have the right custom zone from which you need to pickup the record.
这篇关于无法使用CloudKit在sharedCloudDatabase自定义区域中获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!