Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

ios6 - GKMatchRequest invitation not showing in other device

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...