- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个图像(UIImage 和它的 url),我试图将它作为 CKAsset 发送到 CloudKit,但我遇到了这个错误:Terminating app due to uncaught exception 'NSInvalidArgumentException',原因: “非文件 URL”
。这是代码:
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)
}
})
}
我有 URL,我可以打印它,复制并粘贴到我的导航器,它会显示我的图像!所以,我不知道这里发生了什么......
如果我使用 UIImage 而不是它的 URL 会更容易吗?因为,正如我之前所说,我两者都有!非常感谢任何帮助!谢谢,伙计们!!
最佳答案
根据我的经验,将上传 UIImage
保存为 CKAsset
的唯一方法是:
let data = UIImagePNGRepresentation(myImage); // UIImage -> NSData, see also UIImageJPEGRepresentation
let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent(NSUUID().UUIDString+".dat")
do {
try data!.writeToURL(url, options: [])
} catch let e as NSError {
print("Error! \(e)");
return
}
newUser["photo"] = CKAsset(fileURL: url)
// ...
publicData.saveRecord(newUser, completionHandler: { (record: CKRecord?, error: NSError?) in
// Delete the temporary file
do { try NSFileManager.defaultManager().removeItemAtURL(url) }
catch let e { print("Error deleting temp file: \(e)") }
// ...
}
NSData
初始化
CKAsset
,但尚未完成。
关于ios - 如何将图像作为 CKAsset 正确发送到 CloudKit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36969341/
我有一些数据,比如图片,作为二进制数据存储在核心数据中,并标记为“允许外部存储”。我想将此数据写入 CloudKit。是否可以获取此数据的 URL 并将其传递给 CKAsset,或者以某种方式将此数据
当我将 CKAsset 保存到服务器时,它是否可以在所有设备上使用?如果在某个设备上我不需要其中一项 Assets 怎么办?那里也会占用空间吗? 最佳答案 这取决于。如果设备读取相应的 CKRecor
当我获取包含字符串(或其他)字段的记录时,不到 1 秒: let query = CKQuery(recordType: "Messages", predicate: NSPredicate(for
将我的表格单元格的图像设置为我的“图片”时,我收到此代码中的错误。 func tableView(_ tableView: UITableView, cellForRowAt indexPath:
我正在使用下面的代码来获取 CKAsset 列表,但它一直崩溃并告诉我:“ fatal error :在展开可选值时意外发现 nil” 但是 Assets 列表在CloudKit 仪表板。 你知道我错
我有一个图像(UIImage 和它的 url),我试图将它作为 CKAsset 发送到 CloudKit,但我遇到了这个错误:Terminating app due to uncaught excep
您好,我们想将大型视频文件上传到 CloudKit。 CKAsset 有文件大小限制吗?有一个链接提到大小限制为 15 MB,但这不正确,因为我们尝试上传 300MB 的视频并且已成功上传。另外,该文
我想与未使用我的应用程序的人共享公共(public)数据库中的 CloudKit Assets 。在 CKAsset 类中,只有一个 fileURL 属性,它指向一个本地文件,因此没有给出 URL。
我有一个图像(UIImage 和它的 url),我试图将它作为 CKAsset 发送到 CloudKit,但我遇到了这个错误:Terminating app due to uncaught excep
我在 cloudkit 数据库中有一个可选图像(已检查数据库,如果我在测试中添加它,图像就在那里)。我创建了一个类,将记录字段初始化为我在 tableview 中使用的变量。我也有一个自定义单元格。但
我正在编写的应用程序将允许人们存储多张照片,并将它们与单个对象相关联。 我想我会使用 CloudKit 将这些图像存储为 CKAssets。 在 CloudKit 中,除了其他属性列表类型之外,我还可
我正在使用 CloudKit,在加载数据时,我会检查代码中 CKAsset 是否为 nil,例如: let img = result.value(forKey: "Picture") as! CKAs
如何检查使用 CKAsset 存储的图像在 CloudKit 中是否发生了变化? CKNotification 文档说了 desiredKeys: 数组中最多可以包含三个键。 对于您指定的键,允许的值
有没有办法将 CKAsset 照片异步加载到 UICollectionView 中?眼下,在 CKDatabase performQuery 的 queryCompletionHandler 中,我得
我正在加载一个图像 TableView ,这些图像是作为 CKAssets 从公共(public) CloudKit 数据库中获取的。但是,在将正确的图像加载到自定义 UITableview 单元格的
我也在 CKAsset 的客户端和 fileUrl 上缓存 CKRecord。 fileUrl 可以不时更改吗? Assets /数据本身没有变化。 最佳答案 Assets 的 fileURL 不会改
我正在开发一个应用程序,该应用程序使用 CloudKit 将图像文件存储和检索为 CKAsset 对象。通常,这很好用,我喜欢 CloudKit 的小学习曲线。不过,我会定期遇到这个特殊问题,即图像要
我正在使用 CloudKit 作为我的 iOS 应用程序的服务器后端。我用它来存放一些相对静态的数据以及一些图像 (CKAsset)。当我真正从公共(public)数据库中获取这些 Assets 时,
我有一个简单的 TableView,其中包含从 CloudKit 中提取的文本和图像。我试图在选择时将该数据传递给detailViewController,我可以获取文本,但我坚持通过prepareF
我在数组中有一个 CKRecords 数组。使用表格,我希望使用 SDWedImage 作为我的记录中一个 CKAsset/Image 的缓存。 我试过的代码: override func table
我是一名优秀的程序员,十分优秀!