是否可以使用任何框架从watchos 2中的URL加载图像?我试过SDWebImage,但它不支持watchos2?
答案 0 :(得分:0)
它没有框架,但我写了这个扩展名:
extension WKInterfaceImage {
public func imageFromUrl(_ urlString: String) {
if let url = NSURL(string: urlString) {
let request = NSURLRequest(url: url as URL)
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in
if let imageData = data as Data? {
DispatchQueue.main.async {
self.setImageData(imageData)
}
}
});
task.resume()
}
}
}
只需将wKInterfaceImage添加到watchOS故事板,附加它然后调用即可
imageView.imageFromUrl("https://something")
让我知道它是否有效!