3

Thank you for taking the time to read this post. I am pretty new to coding, so maybe my issues trying to implement CKShare with SwiftUI are due to a basic concept understanding, but I have been working on this for a few days and I can´t figure it out on my own.

I have checked this: "SwiftUI and UICloudSharingController hate each other", but I couldn't implement the solution suggested, perhaps because I started directly on SwiftUI and I do not understand how Swift works well enough.

I would like to share a CKRecord on a custom zone of a user's private database. I would rather not use Apple's standard screens for adding and removing people (UICloudSharingController) as I found it doesn't match with my users' natural journey.

I coded the lines below to User1 to create a CKShare and include as participants the CKUserIdentit of User2. I then captured the url for User2, so they can accept the share.

On the Cloudkit dashboard, I can see the "cloudkit.share" type record on the User1's private database. User2 does appear on the Sharing Participants Field as Type: User and Acceptance: Invited.

However, once User2 opens the url on a browser as an iCloud registered user, the following error is shown:

iCloud has stopped responding

REPORTED ERROR TITLE A non-empty string is required.

REPORTED ERROR TYPE UNHANDLED_EXCEPTION

ERROR CONTEXT undefined

Has anyone dealt with something similar before? Is there any other way to include a known app's user on a CKShare?

Thank you in advance for your help.

Here my code:

let share = CKShare(rootRecord: recordEquipo)
share[CKShare.SystemFieldKey.title] = "Equipo" as CKRecordValue?
share[CKShare.SystemFieldKey.shareType] = "Some type" as CKRecordValue?
let fetchParticipantsOperation: CKFetchShareParticipantsOperation = CKFetchShareParticipantsOperation(userIdentityLookupInfos: [CKUserIdentity.LookupInfo(emailAddress: DTMemail)] )
fetchParticipantsOperation.fetchShareParticipantsCompletionBlock = {error in
    if let error = error {
        print("error for completion" + error.localizedDescription)
        DispatchQueue.main.async {
            completion(.failure(error))
        }
    }
}
fetchParticipantsOperation.shareParticipantFetchedBlock = {participant in
    participant.permission = .readWrite
    share.addParticipant(participant)
    let modifyOperation: CKModifyRecordsOperation = CKModifyRecordsOperation(recordsToSave: [recordEquipo, share], recordIDsToDelete: nil)
    modifyOperation.savePolicy = .ifServerRecordUnchanged
    modifyOperation.perRecordCompletionBlock = {record, error in
        if let error = error {
            print("error for completion" + error.localizedDescription)
            completion(.failure(error))
        }
    }
    modifyOperation.modifyRecordsCompletionBlock = {records, recordIDs, error in
        guard let ckrecords: [CKRecord] = records, let _: CKRecord = ckrecords.first, error == nil else {
            print("error in modifying the records " + error!.localizedDescription)
            completion(.failure(error!))
            return
        }
        if (share.url != nil) {
            completion(.success(share.url!))}

    }

    baseDatosPrivada.add(modifyOperation)
}
contenedor.add(fetchParticipantsOperation)
  • I found where the issue was, finally! The url was created correctly but it needed to be opened using UIApplication.shared.open(URL(string: url)!) – Alejandro Cuartas Apr 23 '20 at 08:46

0 Answers0