2017-03-01 24 views
0

我有一個使用SDWebImage顯示一些遠程內容的iMessage應用程序。圖像被下載並緩存在磁盤上。選擇圖像後,我想將它作爲普通的UIImage(不是MSMessage)附加到消息中。通過SDWebImage下載UIImage的MSConversation.insertAttachment

下面是我使用

// 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)") 
    }) 

這裏代碼的消息是什麼樣子

enter image description here

這似乎是消息框架無法找到該路徑下的圖像。

注:點擊發送後,我的iMessage應用程序崩潰「MobileSMS意外退出」。

+0

最明顯的問題是,你有沒有證實沒有實際上是在那個URL的形象? –

+0

是的,如果我使用UIImage(contentsOfFile:fileUrlString),正確的圖像在那裏 – adamF

回答

0

我發現我需要使用

let fileUrl = URL(fileURLWithPath: fileUrlString)

希望這有助於別人