Can I encode a UIImage into the URL that is sent with an MSMessage in an iMessage app extension?

475 Views Asked by At

I am trying to send an image along with the message that my app creates and inserts to send to other users. The image will be the same image used in the layout property of the message, but there is apparently no way to access the image property on the layout of the message on the receiving user's end.

Is it possible to send the image in the URL attached to the message and then access it on the second user's instance of the app? How could I go about this?

2

There are 2 best solutions below

1
On

As iMessage url scheme supports 5000 characters as written in apple documentation: https://developer.apple.com/reference/messages/msmessage/1649739-url

You can use convert your UIImage to NSData and then convert NSData to String and send the string in the url scheme. To retrieve, decode from string to UIImage.

E.g.:

let image = UIImage.init(named: "myImage.png")
let data = UIImagePNGRepresentation(image!)
let strImageData = data?.base64EncodedString(options: .lineLength64Characters)

Hope this helps

0
On

A couple ideas:

  1. Implement CloudKit to save/request the image (or another 'cloud' solution) and use message.url to share the image's url
  2. If the image is created and not an asset, use the message.url to carry "instructions" for rebuilding if possible?