无法初始化游戏中心匹配?

时间:2013-01-22 00:59:55

标签: iphone ios objective-c game-center gamekit

我正在尝试创建一个实时匹配。我可以成功验证玩家,然后出现标准的“邀请朋友玩”屏幕。我正在测试的是在我的iPhone和iPad上同时使用两个不同的用户启动应用程序。然后我将播放器邀请发送到一个设备并接受它。问题是,此时,我的任一设备都不会调用matchmakerViewController:didFindMatch方法。我究竟做错了什么?如果您需要我解释更多细节,请在下方发表评论:

- (void) authenticateLocalPlayer
{
    //Successfully autheticates player
    [self installInvitationHandler];
    [self createMatch];
}

- (void) createMatch
{
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
    GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
    mmvc.hosted = NO;
    mmvc.matchmakerDelegate = self;
    [self presentViewController:mmvc animated:YES completion:nil];
}


- (void) installInvitationHandler
{
    [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
        // Insert game-specific code here to clean up any game in progress.
        if (acceptedInvite)
        {
            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite];
            mmvc.matchmakerDelegate = self;
            [self presentViewController:mmvc animated:YES completion:nil];
        }
        else if (playersToInvite)
        {
            [alert show];
            [self createMatch];
        }
    };
}  


- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    [self dismissViewControllerAnimated:YES completion:nil];
    self.myMatch = match;
    if (!self.matchStarted && match.expectedPlayerCount == 0)
    {
        self.matchStarted = YES;
        [self performSegueWithIdentifier:@"gameSegue" sender:self];
    }
}

0 个答案:

没有答案