Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GameCenter Invitation Handler

trying to implement a multiplayer. Using the sample from Game Center - Sending and receiving data.

Everything seems okay, but in apple documentation there is also said about invitation handler.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
   // Insert application-specific code here to clean up any games in progress.
   if (acceptedInvite) {
        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    } else if (playersToInvite) {
        GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
        request.minPlayers = 2;
        request.maxPlayers = 4;
        request.playersToInvite = playersToInvite;

        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    }
};

The problem is quite simple: I do not know where to add this code.

like image 667
0xDE4E15B Avatar asked Jan 09 '11 13:01

0xDE4E15B


1 Answers

As stated in the docs

Your application should set the invitation handler as early as possible after your application is launched; an appropriate place to set the handler is in the completion block you provided that executes after the local player is authenticated.

Somewhere in your code, you should have authenticated the local player with something like this

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    if (error == nil) {
        // Insert your piece of code here
    } else {
        // Handle the error
    }
}];

Hope that helps

like image 143
Jilouc Avatar answered Oct 11 '22 16:10

Jilouc