Sending an object with MSMessage

On WWDC Apple said the new messages protocol would allow the creation of games.


I believed that (silly me) and started to started to create a game.


here are the problems so far:


1. It is not clear how the message is really sent. Apple say "user should tap a button to send the message". What button, how do I setup that button?

2. icecream builder sample code is broken, does not even compile.

3. I need to pass an object that represents the status of the game with the message. How can I pass that object? Using the URL as some suggested? If this is the blessed method it is a joke. I have imagined doing this:


a) creating a class, lets say `CurrentPlay` with all the stuff I need to send and making it `NSCoding` compatible.

b) create a `MSMessage` subclass

c) create, on that latter, a property of kind `CurrentPlay`.


Now I can send a custom MSMessage around and it will encapsulate the data I need.


Can I do that?


Please explain 1 and 3.

I agree the documentation is not super clear and the Ice Cream Builder code not compiling does not help.


So far, I have been able to create a new message by executing the code below in a UIViewController which inherits from MSMessagesAppViewController. I have yet to figure out a way to get the activeConversation thread to insert into, as calling this on the controller returns nil. In regards to your other questions, you do not create a send button, this exists in iMessage. Creating a message simply places it into the input field for the user to send. This makes sense, as some developers would have surely abused auto-sending capability. As far as passing your game-variables and state, the URL would be a great way to do it. You could add the key-value pairs into the URL as necessary and parse on the recipents end.


MSConversation *conversation = [MSConversation new];
if (conversation) {
    MSMessageTemplateLayout *layout = [[MSMessageTemplateLayout alloc] init];
    layout.caption = @"Caption";
    layout.subcaption = @"subcaption";

    MSMessage *message = [[MSMessage alloc] init];
    message.URL = [NSURL URLWithString:@"www.example.com"];
    message.layout = layout;

    [conversation insertMessage:message completionHandler:^(NSError *error) {
        if (error) {
            NSLog(@"Error sending message %@", [error localizedDescription]);
        }
    }];
}
Sending an object with MSMessage
 
 
Q