gpt4 book ai didi

ios - Cloudkit: "ZoneId provided doesn' t 匹配目标区域”

转载 作者:搜寻专家 更新时间:2023-10-30 23:02:05 24 4
gpt4 key购买 nike

我有这段代码:

func saveProfileForCheck(check: Check) {
let toSave = CKRecord(recordType: "Check", zoneID: sharedStore.checksID!)
let profile = check.profile as Profile!
toSave.setValue(NSString(format: "%i", check.closed), forKey: "closed")
toSave.setValue(check.date, forKey: "date")
toSave.setValue(NSString(format: "%i", check.paid), forKey: "paid")
toSave.setValue(CKReference(recordID: profile.dbRecordID, action: CKReferenceAction.DeleteSelf), forKey: "profile")

let operation = CKModifyRecordsOperation(recordsToSave: [toSave], recordIDsToDelete: [check.id])
operation.modifyRecordsCompletionBlock = { (savedRecords, deletedRecordIDs, error) in
if error != nil {
self.delegate?.cloudKitReturnedError(error!)
} else {
self.modifiedCheck(check, newRecord: savedRecords![0] as CKRecord )

}
}
privateDB.addOperation(operation)
}

它应该在我的 Checks RecordZone 中的 Check 对象上保存一个 profile 属性。当我触发这个函数时,我得到这个错误:

 <CKError 0x7f8c2046d630: "Partial Failure" (2/1011); "Failed to modify some records"; uuid = EF4CCE3F-3CDB-4506-BA43-464D7D9BD0F6; container ID = "mycontainer"; partial errors: {
130BD962-295C-4601-9343-2E4F4014C8C7:(Checks:__defaultOwner__) = <CKError 0x7f8c2045c680: "Invalid Arguments" (12/2006); server message = "ZoneId provided doesn't match target zone">
... 1 "Batch Request Failed" CKError's omited ...

}>

我尝试了几件事:

  • 检查了 zoneID 是否真的正确。
  • 在方法中将 zoneID 硬编码为 CKRecordZoneID 对象。
  • 在 google 和 SO 上查找错误,没有结果。

请注意,sharedstore.checksID 是一个实际 ID 而不是字符串,它是在获取所有记录区域时在应用启动时创建的。

我该如何解决这个错误?任何建议将不胜感激。

最佳答案

你必须在操作上设置 zoneID,比如:

    operation.zoneID = CKRecordZoneID(zoneName: sharedStore.checksID!, ownerName: "your name")

更新:如下所述,.zoneID 仅适用于 CKQqueryOperation 而不是 CKModifyRecordsOperation

我相信只能将 CKReference 设置为同一区域中的记录。是这样吗?如果没有,那么您可以尝试在没有该引用的情况下保存记录吗?

来自文档:

Treat each custom zone as a single unit of data that is separate from every other zone in the database. Inside the zone, you add records as you would anywhere else. You can also create links between the records inside a zone by using the CKReference class. However, the CKReference class does not support cross-zone linking, so each reference object must point to a record in the same zone as the current record

更新:如果引用的源和目标位于默认区域中,则可以跨数据库(公共(public)和私有(private))添加引用。

关于ios - Cloudkit: "ZoneId provided doesn' t 匹配目标区域”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33257343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com