我正在尝试拍照并将图像上传到iCloud数据库,但我不断收到错误:输入' UIImage'不符合协议' CKRecordValue'
我尝试用来上传文件的代码如下:
data.setObject(picFile.image, forKey: "picture")
代码行是否有问题,或者我错过了其他内容?
答案 0 :(得分:0)
我不得不将其转换为CKAsset。我使用了以下代码:
let imageData = UIImageJPEGRepresentation(picFile.image, 1)
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentDirectory = paths[0] as String
let myFilePath = documentDirectory.stringByAppendingPathComponent("picture")
imageData.writeToFile(myFilePath, atomically: true)
let url = NSURL(fileURLWithPath: myFilePath)
let asset = CKAsset(fileURL: url)
data.setObject(asset, forKey: "picture"