Cannot share with UICloudSharingController; vanishes with "uploading" message
Asked Answered
H

1

6

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)
        }
    }
}
Hussein answered 30/8, 2020 at 22:14 Comment(1)
When the UICloudSharingController crashes it gives error: 2020-08-31 22:33:46.303978-0500 rpxg[3789:1613179] [CK] Got a connection error for operation 49B9977581013179: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.cloudd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.cloudd}Hussein
I
0

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

Imbibition answered 26/3, 2021 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.