Game Center inviting friends programmatically
Asked Answered
P

1

4

I'm facing difficulty inviting a friend to the match.

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; 
    request.minPlayers = 2;
    request.maxPlayers = 2;
    request.playersToInvite = [NSArray arrayWithObjects: @"G:1102359306",nil ];


//  GKMatchmakerViewController *mv = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
//  [self presentModalViewController:mv animated:YES];


    [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
        if (error) {
            NSLog([error description]);
        }
        else if (match != nil) {NSLog(@"good match");
            //self.chatMatch = match;
            //self.chatMatch.delegate = self;       
            //[self chatReady];
        }
        else {
            NSLog(@"other error");
        }

    }];

The problem is I never receive the invitation notification on second device logged to the account - G:1102359306. When I use GKMatchmakerViewController (uncomment above 2 lines) and comment GKMatchmaker block I have automatically checked the good friend - G:1102359306 and when I invites him the notification with accept/decline is shown, that's how I know it's correct.

Do you see anything wrong with the code above? I want to use my own UI to handle the multiplayer mode. The strange problem is I also don't see in console any logs good match/other error, and the [error description] is only printed when I call the above code twice - it says that the previous req was canceled.

Prissy answered 7/11, 2010 at 12:54 Comment(0)
C
2

You cannot programmatically invite a specific set of players to a match. The findMatchForRequest:withCompletionHandler: documentation says this:

The match request’s playersToInvite property is ignored; to invite a specific set of players to the match, you must display a matchmaker view controller.

There is no public API that does what you want.

Caper answered 2/6, 2012 at 20:34 Comment(2)
In iOS 6 you can now do this, i.e. the playersToInvite property is no longer ignored.Sammer
@Sammer that is true, however you still cannot programmatically intercept invites using handleInviteFromGameCenter as that call appear to be triggered only from the Game Center View Controllers.Franciscafranciscan

© 2022 - 2024 — McMap. All rights reserved.