Alessandro is right, this is not explained in the WWDC 2013 video. I struggled with this myself.
I think you're on the right track, you just have a couple logic errors. I don't understand these two lines:
MCSession *session = [ArrayInvitationHandler objectAtIndex:0];
void (^invitationHandler)(BOOL, MCSession *) = [ArrayInvitationHandler objectAtIndex:0];
The object stored in your array is just your handler. The reason you're getting that crash is that the browser is seeing that accept
is true and trying to connect the peer to the session, but the session you're giving it back is nil. To fix this, you want to pass back a new session that you create.
At first I was confused by the notion of creating a new session when one has already been created by the browser side, but then I realized that we don't get that session from the browser anywhere, and we can't really pass it back into the invitation handler if it doesn't exist!
So yeah, do this instead:
BOOL accept = (buttonIndex != alertView.cancelButtonIndex) ? YES : NO;
// respond
MCSession *session;
if(accept) {
session = [[MCSession alloc] initWithPeer:peer];
session.delegate = self;
}
void (^invitationHandler)(BOOL, MCSession *) = [ArrayInvitationHandler objectAtIndex:0];
invitationHandler(accept, session);