Cannot share with UICloudSharingController; vanishes with "uploading" message

315 views Asked by At

while presenting the UICloudSharingController on top of a view, it presents the screen and when I select the messages option to send a message to a person whom I want to share with, it gives a spinning wheel with "uploading" message and vanishes - attachedscreenshot.

However when I go to cloudkit dashboard the root record has been shared. But I cannot share it with specific person. Is it because it has shared global? How can I fix it?

self.shareInfraRecord(zoneID: appDelegate.privateContactZoneID, completion: { (status) in
     if ( status == false) {
             return
      }
    })

func shareInfraRecord(zoneID: CKRecordZone.ID, completion: @escaping(Bool) -> Void) {
    
    if let rootRecord = self.rootRecord {
        if self.rootRecord?.share == nil {
            let sharingController = UICloudSharingController { (controller, preparationHandler: @escaping (CKShare?, CKContainer?, Error?) -> Void) in
                
                let shareID = CKRecord.ID(recordName: UUID().uuidString, zoneID: zoneID)
                var share = CKShare(rootRecord: rootRecord, shareID: shareID)
               
                share[CKShare.SystemFieldKey.title] = Cloud.ShareInfrastructure.ContactShareTitleKey as CKRecordValue?
                share[CKShare.SystemFieldKey.shareType] = Cloud.ShareInfrastructure.ContactShareTypeKey as CKRecordValue?
               
                let modifyRecZoneOp = CKModifyRecordsOperation(recordsToSave:[rootRecord, share], recordIDsToDelete: nil)
                modifyRecZoneOp.modifyRecordsCompletionBlock = { (records, recordID, error) in
                    if error != nil {
                        if let ckerror = error as? CKError {
                            if let serverVersion = ckerror.serverRecord as? CKShare {
                                share = serverVersion
                            }
                            completion(false)
                        }
                    }
                    preparationHandler(share, self.defaultContainer, error)

                }
                self.privateDB?.add(modifyRecZoneOp)
            }
        
            sharingController.availablePermissions = [.allowReadOnly, .allowPrivate]
            sharingController.delegate = self
            sharingController.popoverPresentationController?.sourceView = self.view
        
            self.present(sharingController, animated:true, completion:nil)

    } else {
            let shareRecordID = rootRecord.share!.recordID
            let fetchRecordsOp = CKFetchRecordsOperation(recordIDs: [shareRecordID])
        
            fetchRecordsOp.fetchRecordsCompletionBlock = { recordsByRecordID, error in
                guard error == nil, let share = recordsByRecordID?[shareRecordID] as? CKShare  else {
                    if let ckerror = error as? CKError {
                        self.aErrorHandler.handleCkError(ckerror: ckerror)
                        //self.saveToCloudKitStatus(recordName: myRecordName, success: false)
                    }
                    completion(false)
                    return
                }
               
                DispatchQueue.main.async {
                    let sharingController = UICloudSharingController(share: share, container: self.defaultContainer!)
                    completion(true)
                    //completionHandler(sharingController)
                }
            }
            self.privateDB?.add(fetchRecordsOp)
        }
    }
}
1

There are 1 answers

0
goddamnyouryan On

This might be a bit late but I was running into this issue too, while using NSPersistentCloudKitContainer and it seems the issue was just making sure that my iCloud container name in the Capabilities section of the settings matched my app bundle name ie iCloud.com.goddamnyouryan.MyApp