【问题标题】:MSConversation.insertAttachment with UIImage downloaded via SDWebImage通过 SDWebImage 下载的带有 UIImage 的 MSConversation.insertAttachment
【发布时间】: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


【解决方案1】:

发现需要使用

let fileUrl = URL(fileURLWithPath: fileUrlString)

希望这对其他人有帮助

【讨论】:

  • 你能成功发送 UIImage 吗?
猜你喜欢
  • 2018-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-08
  • 1970-01-01
  • 2020-04-15
  • 2018-06-09
相关资源
最近更新 更多