在CKModifyRecordsOperation中保存CKRecord和CKShare时出错

时间:2016-11-16 20:19:55

标签: swift cloudkit

我正在尝试将CKRecord(已经创建并保存到数据库中)和一个新的CKShare保存到它但我不断收到此错误:可选(“无法修改某些记录”) 。这是我的代码:

    let csc = UICloudSharingController { controller, preparationCompletionHandler in

        let share = CKShare(rootRecord: user)
        share[CKShareTitleKey] = "My Share" as CKRecordValue
        share.publicPermission = .readWrite

        let mro = CKModifyRecordsOperation(recordsToSave: [user, share], recordIDsToDelete: nil)

        mro.timeoutIntervalForRequest = 10
        mro.timeoutIntervalForResource = 10

        mro.modifyRecordsCompletionBlock = { records, recordIDs, error in
            if error != nil {
                print("ERROR IN MODIFY RECORDS COMPLETION BLOCK\n")
                print(error?.localizedDescription)
            }
            preparationCompletionHandler(share,CKContainer.default(), error)
        }
        privateData.add(mro)
    }
    csc.availablePermissions = [.allowPrivate,.allowReadWrite]
    self.present(csc, animated:true)
}

问题在于此方法: modifyRecordsCompletionBlock 。有人可以解释一下为什么会这样吗?

提前致谢!

2 个答案:

答案 0 :(得分:1)

我明白了

您所要做的就是创建一个私人自定义CKZone并将CKRecord和CKShare保存在其中,您无法使用默认的区域云套件给您!

答案 1 :(得分:0)

要留下共享记录,您必须从共享数据库中删除 CKShare 记录,否则会出错。