I have an image (UIImage and its url, too), and I'm trying to send him to CloudKit how CKAsset, but I have this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Non-file URL'. Here is the code:
override func viewDidLoad() {
super.viewDidLoad()
send2Cloud()
}
func send2Cloud() {
let newUser = CKRecord(recordType: "User")
let url = NSURL(string: self.photoURL)
let asset = CKAsset(fileURL: url!)
newUser["name"] = self.name
newUser["photo"] = asset
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(newUser, completionHandler: { (record: CKRecord?, error: NSError?) in
if error == nil {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
print("User saved")
})
} else {
print(error?.localizedDescription)
}
})
}
I have a URL, I can print it, copy and paste it into my navigator, and it will show my image! So, I do not know what is going on here ...
Would it be easier if I worked with UIImage instead of the url? Because, as before, I have both! Any help is much appreciated! Thanks guys!
source
share