let share = CKShare(rootRecord: infraRecord)
// save
let op: CKFetchShareParticipantsOperation = CKFetchShareParticipantsOperation(userIdentityLookupInfos: lookupInfos)
op.fetchShareParticipantsCompletionBlock = { error in
if let error = error {
print("error: ", error)
completion(false, error)
}
}
op.shareParticipantFetchedBlock = { participant in
participant.permission = .readOnly
share.addParticipant(participant)
let modOp: CKModifyRecordsOperation = CKModifyRecordsOperation(recordsToSave: [infraRecord, share], recordIDsToDelete: nil)
modOp.savePolicy = .ifServerRecordUnchanged
modOp.perRecordCompletionBlock = {record, error in
print("record completion \(record) and \(String(describing: error))")
}
modOp.modifyRecordsCompletionBlock = {records, recordIDs, error in
if let error = error {
print("error in modifying the records: ", error)
}
else if let anURL = share.url {
// update the location CKRecord with share URL
self.updateLocationPublicRecord(withShareUrl: anURL.absoluteString, locationRecord: locationRecord, completion: { (status, error) in
if let error = error {
print("error: ", error)
}
})
print("share url \(String(describing: share.url))")
}
completion(true, nil)
}
self.privateDB?.add(modOp)
//completion(true, nil)
}
self.defaultContainer?.add(op)
要访问共享,我首先尝试从共享数据库中获取记录区
Code Block
func getRecordZones(completion: @escaping (CKRecordZoneID?, Error?) -> Void) {
self.sharedDB?.fetchAllRecordZones(completionHandler: { (ckrecordZones, error) in
guard error == nil else {
if let ckError = error as? CKError {
self.aErrorHandler.handleCkError(ckerror: ckError)
}
completion (nil, error)
return
}
if let recordZones = ckrecordZones {
for i in 0 ..< recordZones.count{
// find the zone you want to query
if recordZones[i].zoneID.zoneName == Cloud.SharedZone.UserProfile.ZoneName {
completion (recordZones[i].zoneID, nil)
}
}
}
})
}
我没有从共享数据库中获得任何记录区。当我转到 cloudkit 仪表板时,我在共享数据库中看不到任何共享区域。为什么共享 URL 被分类并且 CKShare 工作后共享记录区域不存在?如何使这项工作?