Like others, you cannot get the URL of CKAsset. Thus, your best options are: 1. Use a fetch operation with progress on each UIImageView. I created a custom one that shows the progress for the user. The cache is not included, but you can create a class and accept NSCoding and save the entire entry in the cache. Here you can see a selection in which I have a completion to send the object back to where I call it, to combine it with my other data.
// only get the asset in this fetch. we have everything else
let operation = CKFetchRecordsOperation (recordIDs: [myRecordID])
operation.desiredKeys = ["GameTurnImage"] operation.perRecordProgressBlock = { record,progress in dispatch_async(dispatch_get_main_queue(), { self.progressIndicatorView.progress = CGFloat(progress) }) } operation.perRecordCompletionBlock = { record,recordID,error in if let _ = record{ let asset = record!.valueForKey("GameTurnImage") as? CKAsset if let _ = asset{ let url = asset!.fileURL let imageData = NSData(contentsOfFile: url.path!)! dispatch_async(dispatch_get_main_queue(), { self.image = UIImage(data: imageData) self.progressIndicatorView.reveal() }) completion(asset!) } } } CKContainer.defaultContainer().publicCloudDatabase.addOperation(operation)
Another option is to store the images on an AWS server or something comparable, and then you can use something like SDWebImage to do the whole cache or heavy lifting and save the line in CKRecord for the image.
I asked several people about the CKAsset function to open the URL. I don't know about JS Api for CloudKit, but there may be a way to do this with this, but I will let others chat with it.
source share