I'm creating a real time matches game and I'm confused as to how to deal with game invitations? For instance, a player on one device can invite his friends to a match and then an invitation banner will appear on the friends' devices. They can tap on the banner and accept the invitation. Now, this works fine if the friend has run the app before and has installed the below invitation handler (installed in the 2nd view controller of the app)
- (void) installInvitationHandler
{
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
// Insert game-specific code here to clean up any game in progress.
if (acceptedInvite)
{
if(self.myConnectingVC) return;
else if(self.myMatchmakerVC)
{
[self dismissViewControllerAnimated:YES completion:^{
self.myMatchmakerVC = nil;
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite];
mmvc.matchmakerDelegate = self;
self.myConnectingVC = mmvc;
[self presentViewController:mmvc animated:YES completion:nil];
}];
}
else
{
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite];
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
}
else if (playersToInvite)
{
[self createMatchWithPlayersToInvite:playersToInvite];
}
};
}
The problem is, what do I do if the friend has never run the app before or if the friend has not progressed far enough in the app to reach the installInvitationHandler
method? If this happens, if the friend taps on the invitation banner, the app will open but it will not accept the invitation.