一、新建一個類WxImageDownloader.swiftswift
二、在類中實現代碼:url
import UIKit import WeexSDK import Kingfisher class WXImageOperation: NSObject, WXImageOperationProtocol { var task: RetrieveImageDownloadTask? init(task: RetrieveImageDownloadTask?) { self.task = task } func cancel() { task?.cancel() } } class WxImageDownloader: NSObject, WXImgLoaderProtocol { func downloadImage(withURL url: String!, imageFrame: CGRect, userInfo options: [AnyHashable : Any]! = [:], completed completedBlock: ((UIImage?, Error?, Bool) -> Void)!) -> WXImageOperationProtocol! { return WXImageOperation.init(task: ImageDownloader.default.downloadImage(with: URL.init(string: url)!, completionHandler: { (image, error, url, data) in completedBlock?(image, error, data != nil ? true : false) })) } }
三、在AppDelegate註冊handler:code
WXSDKEngine.registerHandler(WxImageDownloader(), with: WXImgLoaderProtocol.self)