Skip to content

Instantly share code, notes, and snippets.

@kwylez
Last active February 6, 2018 14:46
Show Gist options
  • Save kwylez/b773bdfc4033c1bd545f63f372306c7a to your computer and use it in GitHub Desktop.
Save kwylez/b773bdfc4033c1bd545f63f372306c7a to your computer and use it in GitHub Desktop.
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