I just figured it out by looking at the Apple Ice Cream Code Sample .
Decision
When creating the MSMessage that you are about to send, use the NSURLComponents object to save user information in the QueryItems property.
An example :
MSMessage* message; NSURLComponents* urlComponents; // init message = [[MSMessage alloc] init]; urlComponents = [NSURLComponents componentsWithURL:[NSURL URLWithString:@"http://yourwebsite.com"] resolvingAgainstBaseURL:NO]; // Saving Custom Information as query items. [urlComponents setQueryItems:@[[NSURLQueryItem queryItemWithName:@"messageType" value:@"1"], [NSURLQueryItem queryItemWithName:@"username" value:@"Jorge"], [NSURLQueryItem queryItemWithName:@"userId" value:@"99999"], [NSURLQueryItem queryItemWithName:@"userPhoto" value:@"http://yourwebsite.com/9999.jpg"]]]; // Setting message URL [message setURL:[urlComponents URL]];
Final URL :
The final URL added to MSMessage will look like this:
http://yourwebsite.com?messageType=1&username=Jorge&userId=99999&userPhoto=http://yourwebsite.com/99999.jpg
These additional request elements in the URL will be ignored . I mean, if your site is not designed to process these request elements, it simply ignores them when the user picks up this message bubble and opens the URL in the browser from a device with iOS version less than 10 (iOS9, iOS8, ... )
The only drawback that I see here is the disclosure of user information to the user (when opening the URL). Perhaps Apple should create a userInfo property in MSMessage .
Receive message
And this is how you extract information from the received message:
MSMessage* message; NSString* messageType, *username, *userId, *userPhoto; // init message = [self.activeConversation selectedMessage]; if (message) { NSURLComponents *urlComponents; NSArray* queryItems; // Extracting message URL coponents. With this URL we'll able to figure out the type of the message. urlComponents = [NSURLComponents componentsWithURL:[message URL] resolvingAgainstBaseURL:NO]; queryItems = [urlComponents queryItems]; // Extracting info from the query items. for (NSURLQueryItem* item in queryItems) { if ([[item name] isEqualToString:@"messageType"]) messageType = [item value]; else if ([[item name] isEqualToString:@"username"]) username = [item value]; else if ([[item name] isEqualToString:@"userId"]) userId = [item value]; else if ([[item name] isEqualToString:@"userPhoto"]) userPhoto = [item value]; } }
source share