7

リアルタイム マッチ ゲームを作成していますが、ゲームへの招待の処理方法がわかりません。たとえば、あるデバイスのプレーヤーが友人を試合に招待すると、招待バナーが友人のデバイスに表示されます。バナーをタップして、招待を受け入れることができます。現在、友人が以前にアプリを実行し、以下の招待ハンドラー (アプリの 2 番目のビュー コントローラーにインストールされている) をインストールしている場合、これは正常に機能します。

- (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.

4

2 に答える 2

1

アプリの起動直後に、inviteHandler を追加する必要があります。ハンドラーが呼び出されると、GKInvite オブジェクトが渡されます。

[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.
    }
};
于 2013-04-03T21:02:05.970 に答える