My objective: I'm trying to run conditional logic on the share button. If I can detect the record is already shared (i.e. record?.share is not nil), then I want to display the participant management screen; else, I want to display the view that allows you to select how you want to share the item.
Video #226 "What's New in CloudKit" for 2016 says you can just call UICloudSharingController with the share, but when I try the code below I get the standard UICloudSharingController view that lets me pick how I want to share the item:
privateDB.fetch(withRecordID: recordID, completionHandler: { (record, error) in
if error != nil {
print(error)
} else {
let container = CKContainer.default()
let share = CKShare(rootRecord: record!)
// This seems like the only way to call UICloudSharingController without a preparation handler
// as the video suggests
let shareController = UICloudSharingController(share: share, container: container)
shareController.delegate = self
shareController.availablePermissions = [.allowPrivate, .allowReadWrite]
shareController.popoverPresentationController?.sourceView = self.shareButton
self.present(shareController, animated: true)
}
})
I'm also stuck with line 7. How do I create the instance of CKShare I need without creating a new share? Calling record?.share returns a CKReference, not the CKShare I need. But I feel like instantiating a new share isn't the way to go either.
Really struggling without the documentation. If anyone can offer any help, it would go a long way!