2

I am brand new to iMessage App development. Looking at some examples, it looks like the way information is transferred from the sender to the recipient with iMessage Apps is via URLComponents.

  • Is this the only way to send information on iMessage Apps?
  • I am unfamiliar with URLComponents in swift, does the actual URL even matter?

Thanks!!

BostonCam
  • 21
  • 2

2 Answers2

0

MSMessage's url property is where you can store your custom data.

You can use iMessageDataKit library for storing key-value pairs in MSMessage objects. It makes setting and getting data really easy like:

let message: MSMessage = MSMessage()

message.md.set(value: 7, forKey: "user_id")
message.md.set(value: "john", forKey: "username")
message.md.set(values: ["joy", "smile"], forKey: "tags")

print(message.md.integer(forKey: "user_id")!)
print(message.md.string(forKey: "username")!)
print(message.md.values(forKey: "tags")!)

(Disclaimer: I'm the author of iMessageDataKit)

Ahmet Ardal
  • 1,162
  • 1
  • 11
  • 12
0

You can use it w/ native swift as well:

let layout = MSMessageTemplateLayout()
var components = URLComponents()
let caption = URLQueryItem(name: "caption", value: self.melody)
let decodedMelody = URLQueryItem(name: "melody", value: self.melody)

components.queryItems = [caption, decodedMelody]

let message = MSMessage(session: session ?? MSSession())
layout.image = self.screenImage.image

layout.caption = "Melody built with haptic and vibro."
layout.subcaption = "sent via iVibrio"
message.summaryText = "something summary"

message.url = components.url!
message.layout = layout

Here's my complete example how to send data and image via iMessage application

Mikita Manko
  • 1,133
  • 9
  • 9