【问题标题】:Unable to fetch records in a sharedCloudDatabase custom Zone using CloudKit无法使用 CloudKit 获取 sharedCloudDatabase 自定义区域中的记录
【发布时间】:2019-05-16 07:29:48
【问题描述】:

我正在尝试从共享数据库中的自定义区域获取 CloudKit 记录。

在共享过程中已正确创建区域。所以我假设该区域是正确的共享自定义区域(它确实在我的 CloudKit 用户仪表板中,出现在默认容器的 sharedDatabase 下)。

即使使用这段简单的代码来检索记录:

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)
        }
    }
}

我不断收到此错误:(抱歉在之前的帖子中遗漏了!)

<CKError 0x280950840: "Invalid Arguments" (12/1009); "Only shared zones can be accessed in the shared DB">

知道我缺少什么吗?谢谢!

【问题讨论】:

  • 哪个错误? (缺失)
  • 抱歉,跳过了……现在更新了。
  • 也许this post 可以解决您的问题?
  • 很遗憾没有。我确实在共享之前将记录保存在私人用户数据库中。所以记录保存在私有数据库中,然后我共享它,共享导致在接受共享的用户的共享数据库中生成“窗口”。这确实让我感到困惑……shareDB 中的区域确实应该是共享的!

标签: ios swift cloudkit cloudkit-sharing


【解决方案1】:

好吧,我终于想通了。感谢 StackOverflow 上的附加帖子:CloudKit Sharing

您确实必须获取您的自定义区域。但是仅仅给它一个名字是不够的,比如“MyCustomZone”,因为在你的共享数据库中,它变成了MyCustomZone:_acBxxxyyyzzz。 CloudKit 添加的后缀。

如果您没有获取所有共享区域,则您永远不会拥有需要从中获取记录的正确自定义区域。

【讨论】:

  • 你能把你所指的代码贴在这里吗? (获取共享自定义区域等)。真的很感激。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-03
  • 1970-01-01
  • 1970-01-01
  • 2020-06-21
  • 1970-01-01
  • 2016-06-21
  • 2017-07-11
相关资源
最近更新 更多