【发布时间】:2017-07-21 00:17:49
【问题描述】:
我有一个 iMessage 应用程序,它使用 SDWebImage 显示一些远程内容。图像被下载并缓存在磁盘上。选择图像后,我想将其作为普通 UIImage(而不是 MSMessage)附加到消息中。
这是我正在使用的代码
// image is already downloaded
let cache = SDImageCache.shared()
let key = remoteImageUrl
let fileUrlString = cache.defaultCachePath(forKey: key)!
let fileUrl = URL(string: fileUrlString)!
// image holds the correct UIImage
let image = UIImage(contentsOfFile: fileUrlString)
activeConversation?.insertAttachment(fileUrl, withAlternateFilename: "a funny gif", completionHandler: { (error) in
// error is nil here
print("error: \(error)")
})
这是消息的样子
消息框架似乎在该路径中找不到图像。
注意:点击发送后,iMessage 应用崩溃“MobileSMS 意外退出”。
【问题讨论】:
-
显而易见的问题是,您是否验证过该 URL 处确实有图片?
-
是的,如果我使用 UIImage(contentsOfFile: fileUrlString),正确的图像就在那里
标签: ios messages sdwebimage imessage