如何解决CloudKit:如何使用 CKFetchShareParticipants 和 CKModifyRecords 获取共享 URL?
我正在关注此 WWDC video 和一些在线找到的示例代码(遗憾的是 Apple 没有在其 WWDC 演讲中包含示例代码),使用下面的此代码,我的 ckshareParticipant
没问题,但是这块 modoperation.modifyRecordsCompletionBlock
根本没有返回,我做错了什么?
private func share(record: CKRecord) {
let share = ckshare(rootRecord: record)
// save
let operation = CKFetchShareParticipantsOperation(userIdentityLookupInfos: [CKUserIdentity.LookupInfo(emailAddress: "friendsEmail@gmail.com")])
var participants = [ckshare.Participant]()
// Collect the participants as CloudKit generates them.
operation.shareParticipantFetchedBlock = { participant in
participants.append(participant)
}
// If the operation fails,return the error to the caller.
// Otherwise,return the array of participants.
operation.fetchShareParticipantsCompletionBlock = { error in
if let error = error {
print("error: ",error)
} else {
for participant in participants {
print("we have a participant! = \(participant)")
let modoperation: CKModifyRecordsOperation = CKModifyRecordsOperation(recordsToSave: [record,share],recordIDsToDelete: nil)
operation.shareParticipantFetchedBlock = { participant in
participant.permission = .readOnly
share.addParticipant(participant)
modoperation.savePolicy = .ifServerRecordUnchanged
//nothing in this block gets called
modoperation.modifyRecordsCompletionBlock = {records,recordIDs,error in
if let error = error {
print("error in modifying the records: ",error)
} else {
print("TESTING records = \(records) recordIDs = \(recordIDs)")
}
}
}
modoperation.qualityOfService = .userInitiated
container.privateCloudDatabase.add(modoperation)
} //end of for participant in participants
}
} //end of operation.fetchShareParticipantsCompletionBlock
// Set an appropriate QoS and add the operation to the
// container's queue to execute it.
operation.qualityOfService = .userInitiated
container.add(operation) //It was important to make sure this is the same container
}
解决方法
这最终只是一个错字,我只需要删除 operation.shareParticipantFetchedBlock = { participant in
声明下的这一行modOperation
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。