Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Save Custom Info in MSMessage?

In iMessage Extensions for iOS10, when the user taps on the interactive message bubble:

How can you save custom information in the sent message so, when tapped, the extension is able to get that custom information and recognize the type of the tapped message to respond accordingly?

Thanks!

like image 812
jmoukel Avatar asked Aug 24 '16 16:08

jmoukel


1 Answers

Since this is an iOS 10 question, I hope the following answer in Swift will be helpful to others. (Original answer by @jmoukel, just converted to Swift by me).

let message = MSMessage()
guard let url = NSURL(string: "http://yourwebsite.com") else { return }
guard let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) else { return }
urlComponents.setQueryItems([
    "messageType": "1",
    "username":"Jorge",
    "userId":"99999",
    "userPhoto":"http://yourwebsite.com/9999.jpg"
])
message.setURL(urlComponents.URL!)
like image 145
aksh1t Avatar answered Sep 21 '22 10:09

aksh1t