سؤال

The Game Center documentation indicates that the

playersToInvite parameter is non-nil when your application is launched directly from the Game Center application to host a match.

A few people have asked how this works exactly, i.e. there doesn't appear to be a way to select a friend from the Game Center application and invite them to play from Game Center; it only works when you invite in-game. Is this documentation dated or is there a secret way to start a game-specific match from Game Center? I'd like to test my inviteHandler but I've been unable to determine how this parameter is passed to the application.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite)
{
    // clean up games in progress here
    if (acceptedInvite)
    {
        NSLog(@"acceptedInvite %@", acceptedInvite);
        // The acceptedInvite parameter is non-nil when the application receives an 
        // invitation directly from another player.
        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
        mmvc.matchmakerDelegate = self;
        [self disableHomeUI];
        [self presentModalViewController:mmvc animated:YES];
    }
    else if (playersToInvite)
    {
        NSLog(@"playersToInvite %@", playersToInvite);
        // playersToInvite parameter is non-nil when your application is launched 
        // directly from the Game Center application to host a match
        [self disableHomeUI];
        [self doPresentMatchMakerUIWithPlayersToInvite:playersToInvite];
    }
};
هل كانت مفيدة؟

المحلول 2

After launching my application Cee-lo into production, the playersToInvite code became active. This seems to be because the Sandbox version of the Game Center app itself does not allow you to start a game with a player from there, but the production version does. Not a very good test environment if you ask me!

نصائح أخرى

I think the docs do not reflect the current state of affairs. As far as I can tell, the Game Center App does not even offer an interface for inviting friends to play, currently.

Also, check the developer forums (apparently you have ;) ). Someone from Cupertino seems to think it is not possible. So...

There is now a way to use the Game Center app to invite a Game Center friend. It ONLY works if your game calls registerListener: on the localPlayer GKPlayer:

Game Center App -> games tab -> your game -> Players section -> select a player -> "Play a Game"

This will send a push notification invite to the other player. Game does not have to be running on either device. As of iOS7.

This flow also works: Game Center App -> friends tab -> tap a friend -> tap a game in common (your game) -> tap the "..." in the top right corner -> tap "Play"

I could be wrong, but i think it is just the "simulator" that can not invite particular friends to play.

I have been able to use 2 or more iPhones running in the sandbox to invite particular friends to play, and it has worked wonderfully for debugging the invite handler piece of code.

As another poster mentioned, there does not appear to be at this time a way of inviting particular friends to play a particular game from Game Center.

Happy gaming!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top