1
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)

To access the share I first try to get the recordzones from shared database

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)
          }
        }
      }
    })
  }

I dont get any recordzones from shared database. When I go to cloudkit dashboard, I don't see any shared zones in the shared database. Why is it that shared record zone does not exist ever after share URL was cated and CKShare worked? How to make this work?

vrao
  • 545
  • 2
  • 12
  • 33
  • Edits: I see in the cloudkit dashboard there is shared database zone with zone name: userProfileZone and owner name _9d4825db9b0aa911655e420ec0016129. But the below code after fetching CKRecordZone from shared database returns nil self.sharedDB?.fetchAllRecordZones(completionHandler: { (ckrecordZones, error) in if error != nil {print(ckrecordZones?.first?.zoneID.zoneName)} }. I dont know why it is not returning the zone – vrao Jul 29 '20 at 02:56
  • I go the cloud kit dashboard private database and fetch the shared record and then click on the References share Share-1273FA9B-DCDC-4AD1-84B0-AF9178A26B92. Or I click on the linked shared record; I get error: “There was problem resolving the short GUID”. Bad request exception: missing required field ‘value’ Request ID: 45 .e2c7fa-….” Then I went the and copied the short GUID of the shared record and accepted, then it gives error: There was a problem accepting the shared record I don’t know what is going on, totally confusing. – vrao Jul 29 '20 at 04:58
  • Did you ever solve this? – GarySabo May 13 '21 at 02:38
  • No I am working on something else for now. But would like to know how to get it done. – vrao May 14 '21 at 03:48

0 Answers0