无法在 tvOS 应用程序中加载 LCR 图像 [英] Unable to load LCR image in tvOS apps
问题描述
我正在尝试使用 Apple 文档中描述的contentsOfFile"方法在 UIImageView 中加载 LCR 图像,但我收到了 nil 图像错误.谁能确认我们如何从服务器加载 LCR 图像?
I am trying to load LCR image in UIImageView using "contentsOfFile" method as described in apple document but I am getting error with nil image. Can anyone please confirm how we can load LCR images from server?
我正在使用的代码:
UIImage(contentsOfFile: "LCR file url")
我在控制台出错:
BOMStorage BOMStorageOpenWithSys(const char , Boolean, BomSys ): 不能open: '/LCR file url' 没有那个文件或目录
BOMStorage BOMStorageOpenWithSys(const char , Boolean, BomSys ): can't open: '/LCR file url' No such file or directory
我注意到的一件事是它在我的实际网址前添加了/".我认为这是因为它在本地存储中寻找文件.有谁知道解决方法是什么?
One thing I noticed is it adds "/" in front of my actual url. I think its because its looking for files in local storage. Does anyone know whats the solution of it?
我什至尝试使用这个:
下载的文件——使用 imageWithContentsOfFile 加载图像:
Downloaded file—Load images using imageWithContentsOfFile:
但没有用:(
推荐答案
好的,我自己找到了解决这个问题的办法.所以我在这里发帖以防万一其他人面临同样的问题.下面是带有解释的代码:
Ok I kind of found the work around myself for this problem. So I am posting here if in case anyone else is facing same problem. Below is code with explanation:
if let url = NSURL(string: "https://.lcr-file-url") {
if let data = NSData(contentsOfURL: url){
let documents = NSURL(string: NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0])
let writePath = documents!.URLByAppendingPathComponent("file.lcr")
data.writeToFile(writePath.absoluteString, atomically: true)
let image = UIImage(contentsOfFile: writePath.absoluteString)
}
}
基本上我们需要下载图像数据并将其保存在某个本地文件中,然后使用 contentsOfFile 方法来获得实际图像.
Basically we need to download the image data and save it in some local file and use contentsOfFile method to have actual image.
如果有人知道比这更好的解决方案,我会很高兴听到:)
If anyone else know better solution than this, I would be happy to hear :)
这篇关于无法在 tvOS 应用程序中加载 LCR 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!