0

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?

Cody Lucas
  • 682
  • 1
  • 6
  • 23
  • How about just try? Just pass the image as a NSData or Data (swift 3) and see what happen ;) UIImage has init fun that take data – RomOne Oct 24 '16 at 22:57
  • The payload of an MSMessage is a URL though. I can't just send whatever I want with the message, else I could just send the image. – Cody Lucas Oct 24 '16 at 23:12
  • You can convert image into base64 string and send it through URLQueryItem. I hope this could be useful. – Yogesh Mv Oct 25 '16 at 06:32
  • The URL is capped at 5000 characters, the image I converted resulted in 29k characters. Good idea though. – Cody Lucas Oct 26 '16 at 16:56

2 Answers2

2

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?
Zig
  • 2,603
  • 1
  • 14
  • 20
1

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

Subhajit Halder
  • 1,427
  • 13
  • 21
  • Thanks for the recommendation, but I already tried this and the image results in a 29k character string, so it fails. – Cody Lucas Nov 02 '16 at 14:10