Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public func fetchShareURL(_ callback: @escaping ((_ url: URL?) -> Void)) -> Void {
if let localRecordZoneID: CKRecordZoneID = SOUser.localICloudConversationRecordID?.zoneID {
let predicate: NSPredicate = NSPredicate(format: "TRUEPREDICATE")
let query: CKQuery = CKQuery(recordType: CloudKitConverationRecordTypeName, predicate: predicate)
let cloudkitController: CloudKitController = CloudKitController(scope: .private)
cloudkitController.perform(query, inZoneWith: localRecordZoneID, completionHandler: {results, error in
guard let share: CKReference = results?.first?.share else {
callback(nil)
return
}
cloudkitController.fetch(withRecordID: share.recordID, completionHandler: {record, error in
guard let sharedRecord: CKShare = record as? CKShare,
let sharedURL: URL = sharedRecord.url else {
callback(nil)
return
}
callback(sharedURL)
})
})
} else {
callback(nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment