有没有办法用一个UICloudSharingController创建多个CKShares?

时间:2017-12-19 16:17:14

标签: ios swift cloudkit

现在和单人分享我这样做:

//here I have access to record fetched from cloud database
let controller = UICloudSharingController { controller, preparationCompletionHandler in
    let share = CKShare(rootRecord: record)
    share[CKShareTitleKey] = territory.name as CKRecordValue
    share[CKShareTypeKey] = "pl.blueworld.fieldservice" as CKRecordValue
    share.publicPermission = .readWrite

    let operation = CKModifyRecordsOperation(recordsToSave: [record, share], recordIDsToDelete: nil) //what happens if I pass here a three records and three related ckshares?
    operation.savePolicy = .ifServerRecordUnchanged

    operation.modifyRecordsCompletionBlock = { records, recordIds, error in
        preparationCompletionHandler(share, CloudAssistant.shared.container, error) //how can I do it for every created ckshare?
    }

    operation.database = territory.database
    CloudAssistant.shared.operationQueue.addOperation(operation)
}
controller.delegate = self
controller.popoverPresentationController?.barButtonItem = self.collaborateBarButtonItem
present(controller, animated: true)

但我怎么能为2个ckshares做到这一点?有可能吗?

1 个答案:

答案 0 :(得分:1)

当然,在您添加share的位置,只需根据需要设置多个,例如let share1 = ...; let share2 = ...;。然后在CKModifyRecordsOperation初始化程序中,添加每个共享,例如CKModifyRecordsOperation(recordsToSave: [record1, share1, record2, share2]