简体   繁体   中英

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

I'm working on a game center multiplayer app and I've found something that makes me scratch my head. I can receive game invites just fine as long as both devices do not have the GKMatchmakerViewController up and running. However, when both devices have it open and an invitation is sent out, nothing happens after the user selects "Accept" on the alert banner. Are there any good working examples out there that show how to do this? I'm working with Ray Wenderlich's GCHelper and have not made any progress with this issue for weeks.

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

        }


    };

I think the issue is has to do with"

Warning: Attempt to present on while a presentation is in progress!

What do I need to do to fix this?

Looks like the problem was that it wasn't waiting long enough for the controller to be dismissed.

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

Took care of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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