Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with game center invitations, if the friend has not progressed far enough in the app to reach the installInvitationHandler method?

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.

like image 309
Nosrettap Avatar asked Jan 22 '13 18:01

Nosrettap


People also ask

How do you challenge friends on Game Center?

Tap Friends. Tap Add Friends. Enter the phone number or email of the person that you want to invite to be friends in Game Center, or tap the Add button to invite one of your contacts. Once that person accepts the request through the Messages app, you'll be able to see them on your list of friends.

Is Game Center linked to Apple ID?

When you sign in with your Apple ID, you will be signed in to Game Center automatically. Game Center allows you to engage in game-related activities such as participation in leaderboards; multiplayer games; finding, viewing, and challenging friends; and tracking achievements.

How do you check what games are connected to Game Center?

The only way to find out is to login with every known account. Gamecenter accounts are easily changeable and doing so doesn't affect the rest of your device because your Apple-ID/iCloud login is seperated from your Gamecenter account.


1 Answers

You should add the inviteHandler immediately after your app launches. The GKInvite object is passed in when the handler is called.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
    //By the time this block is called, you have already received the
    //invite, it's passed as a parameter
    if (acceptedInvite) {
        //This is your invite
    } else if (playersToInvite) {
        //The player has launched your app from the Game Center app, invite these players.
    }
};
like image 74
dalton_c Avatar answered Nov 15 '22 06:11

dalton_c