GKMatchRequest invitation not showing in other device
Asked Answered
A

2

4

Thanks to the updates to GameKit API in iOS 6, I am finally able to implement my turn-based board game the way it should be, complete with turn timeouts and better programmatic creation of matches. However, I am running into an issue that I cannot seem to solve. My desire is to have Game Center running entirely invisible to the end-user, so that everything is programmatic and uses my own custom interfaces. Therefore, I use my own custom table view to display matches, not the default GKTurnBasedMatchmakerViewController. Right now, I have no problem displaying open matches using the -loadMatchesWithCompletionHandler: method. I also use a custom screen to create a match, with a direct creation for auto-match (not a problem) and a table view that loads Game Center friends of the localPlayer for invitation. Since the playersToInvite attribute can now be filled with playerID's, this is possible in iOS 6.

My main problem is handling the invitation on the recipient's side. I send the invitation with the following code

-(void)invitarAmigoMio:(NSArray*)losAmigos
{

    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
    request.defaultNumberOfPlayers=2;
    request.playersToInvite = losAmigos;
    request.inviteMessage = @"Your Custom Invitation Message Here";



    request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse
                                       response)
    {

        if (response==GKInviteeResponseAccepted)
        {
            NSLog(@"INVITACION ACEPTADA");
        }
        else
        {
            NSLog(@"INVITACION RECHAZADA");

        }
    };

}

I have a delegate that handles the notifications. The following code is launch when the user is authenticated

-(void)registroNotificaciones
{
    NSLog(@"registroNotificaciones");

    [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite* acceptedInvite, NSArray *playersToInvite)
    {
        if(acceptedInvite != nil)
        {
            // Get a match for the invite we obtained...
            [[GKMatchmaker sharedMatchmaker] matchForInvite:acceptedInvite completionHandler:^(GKMatch *match, NSError *error)
             {
                 if(match != nil)
                 {
                     NSLog(@"match != nil: ");

                 }
                 else if(error != nil)
                 {
                     NSLog(@"ERROR: From matchForInvite: %@", [error description]);
                 }
                 else
                 {
                     NSLog(@"ERROR: Unexpected return from matchForInvite...");
                 }
             }];
        }
    };
    NSLog(@"FIN registroNotificaciones");

}

Why notifications are not send?Or notifications are not received?Is there another way to send notification to invite to play a game? I checked and my sandbox accounts of Game Center allow invitations, and I dont know what´s going on

Anticlastic answered 28/4, 2013 at 18:14 Comment(1)
Why you use .inviteHandler if it is deprecated for iOS 7? How to get GKInvite* acceptedInvite by another way?Schechinger
H
3

You did pretty much all that is needed to create the invite; you just need to send it with this code:

[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch* match, NSError *error) {
        if (error)
        {
           //Invite has not been sent
        }
        else if (match != nil)
        {
          //whatever you want to do when the receiver accepts the invite
        }
}];
Hogle answered 18/11, 2013 at 20:55 Comment(0)
S
0

I know you are looking to use custom displays but I haven't made my own view controllers for this, instead I used GKMatchmakerViewController which handles the 'send' invites for me and I think that's what's missing in your code.

Here is my code for that, maybe you can try it and check how GKMatchmakerViewController works internally (if possible):

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; 
request.minPlayers = minPlayers;     
request.maxPlayers = maxPlayers;
request.playersToInvite = pendingPlayersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[myPresentingViewController presentModalViewController:mmvc animated:YES];

I have almost the same code you have that handles the notifications (registroNotificaciones) and it gets executed as soon as the user authenticates with GameCenter and is one of the first things the app does when launched too, from what you say, it looks like this code is working properly, just . Hope it helps!

Sahib answered 30/4, 2013 at 19:51 Comment(1)
Game center invitations are not working this days, I dont know what´s going on with game center SandBox server. I read about that in ios developer forumsAnticlastic

© 2022 - 2024 — McMap. All rights reserved.