繁体   English   中英

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

[英]How do you receive a game center invite when GKMatchmakerViewController is open?

我正在开发一个游戏中心多人游戏应用程序,发现了一些让我挠头的东西。 只要两个设备都没有启动并运行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;

        }


    };

我认为这个问题与“

警告:在演示过程中尝试演示!

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

看起来问题在于没有足够长的时间等待控制器被解雇。

        [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;
                                 }];

照顾它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM