如果朋友在应用程序中没有取得足够的进展来达到installInvitationHandler方法,如何处理游戏中心邀请?

Nos*_*tap 7 iphone objective-c gamekit ios game-center

我正在创建一个实时比赛游戏,我对如何处理游戏邀请感到困惑?例如,一个设备上的玩家可以邀请他的朋友参加比赛,然后邀请横幅将出现在朋友的设备上.他们可以点击横幅并接受邀请.现在,如果朋友之前已经运行了应用程序并安装了以下邀请处理程序(安装在应用程序的第二个视图控制器中),这样可以正常工作

- (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];
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

问题是,如果朋友之前从未运行过应用程序,或者如果朋友在应用程序中没有取得足够进展以达到该installInvitationHandler方法,我该怎么办? 如果发生这种情况,如果朋友点击邀请横幅,应用程序将会打开,但不会接受邀请.

dal*_*ook 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.
    }
};
Run Code Online (Sandbox Code Playgroud)