I am making an iMessage Extension that involves users sending pictures back and forth to one another. They need to both be able to access the images that they receive from each other and use it on their own end. For example, if USER 1 sends a picture of a puppy to USER 2, the image property of the messages layout would be of the puppy. USER 2 should then be able to tap that message, and the puppy load into an image view on screen. So far I don't know how I would do this.
Here's where I set the layout image to that of a puppy.
@IBAction func sendPicturePressed(_ sender: AnyObject) {
if chosenImage.image != nil {
let session = MSSession()
let message = MSMessage(session: session)
let conversation = self.activeConversation
let components = URLComponents()
let layout = MSMessageTemplateLayout()
let image = chosenImage.image
layout.image = image
message.layout = layout
message.url = components.url!
conversation?.insert(message, completionHandler: { (error) in
self.dismiss()
})
}
}
Now when the second user taps the puppy, I want to set an image view on their screen to the puppy. Not exactly sure how, but what I'd LIKE to do is:
override func willBecomeActive(with conversation: MSConversation) {
imageView.image = conversation.selectedMessage.layout.image
//There is no image property to access this like I've provided, that's just what I'm trying to accomplish.
}
You can't access the layout image that send from another user. https://forums.developer.apple.com/thread/53174
What you can, is on the sender side, you not only insert a
MSMessagewith image layout toMSConversation, but also upload an image copy to your server and mark the web image URL inMSMessage.URL.So next time when user select a message, you can unwrap
MSMessage.URLand find the image URL, then download it from your server.