Cannot fetch record zones from shared database

198 views Asked by At
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?

0

There are 0 answers