当GKMatchmakerViewController打开时,您如何收到游戏中心邀请?

时间:2013-05-26 06:04:47

标签: iphone objective-c cocos2d-iphone game-center multiplayer

我正在开发一款游戏中心多人游戏应用程序,我发现了一些让我头疼的东西。只要两个设备都没有启动并运行GKMatchmakerViewController,我就可以收到游戏邀请。但是,当两个设备都打开并发出邀请时,用户在警报横幅上选择“接受”后没有任何反应。有没有什么好的工作实例可以说明如何做到这一点?我和Ray Wenderlich的GCHelper合作,并且几周没有在这个问题上取得任何进展。

    [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite)
    {

        NSLog(@"Received invite!!!");
        self.pendingInvite = acceptedInvite;
        self.pendingPlayersToInvite = playersToInvite;

        Class gcClass = (NSClassFromString(@"GKLocalPlayer"));
        NSString *reqSysVer = @"5.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        BOOL osVersionSupported = ([currSysVer compare:reqSysVer
                                               options:NSNumericSearch] != NSOrderedAscending);

        gameCenterAvailable=gcClass && osVersionSupported;
        if (!gameCenterAvailable) return;

        matchStarted = NO;
        self.match = nil;

        if (acceptedInvite) {
            NSLog(@"pendingInvite != nil");

             AppDelegate *gcdelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;

            [gcdelegate.viewController  dismissModalViewControllerAnimated:YES];
            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:pendingInvite];
            mmvc.matchmakerDelegate = self;
            [gcdelegate.viewController  presentModalViewController:mmvc animated:YES];

            self.pendingInvite = nil;
            self.pendingPlayersToInvite = nil;

            boo_invite=true;


        }
        else {
            NSLog(@"pendingInvite == nil");

            AppDelegate *gcdelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
            [gcdelegate.viewController dismissModalViewControllerAnimated:NO];

            request = [[GKMatchRequest alloc] init];
            request.minPlayers = 2;
            request.maxPlayers = 4;
            request.playersToInvite = pendingPlayersToInvite;

            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
            mmvc.matchmakerDelegate = self;

            [gcdelegate.viewController dismissModalViewControllerAnimated:YES];

            self.pendingInvite = nil;
            self.pendingPlayersToInvite = nil;

        }


    };

我认为这个问题与“

有关
  

警告:尝试出席   当一个演示文稿在   进步!

我需要做些什么来解决这个问题?

1 个答案:

答案 0 :(得分:0)

看起来问题是它没有等待控制器被解雇的时间。

        [gcdelegate.viewController  dismissViewControllerAnimated:YES
                                 completion:^{
                                     GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:pendingInvite];
                                     mmvc.matchmakerDelegate = self;
                                     [gcdelegate.viewController presentModalViewController:mmvc animated:YES];
                                     self.pendingInvite = nil;
                                     self.pendingPlayersToInvite = nil;
                                     boo_invite=true;
                                 }];

照顾它。