GKMatchRequest邀请未在其他设备中显示 [英] GKMatchRequest invitation not showing in other device

查看:134
本文介绍了GKMatchRequest邀请未在其他设备中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于iOS 6中对GameKit API的更新,我终于能够以应有的方式实现我的回合制棋盘游戏,完成转弯超时和更好的程序化比赛创建。但是,我遇到了一个我似乎无法解决的问题。我的愿望是让游戏中心对最终用户完全不可见,因此一切都是程序化的,并使用我自己的自定义界面。因此,我使用自己的自定义表视图来显示匹配项,而不是默认的GKTurnBasedMatchmakerViewController。现在,使用-loadMatchesWithCompletionHandler:方法显示打开的匹配项没有问题。我还使用自定义屏幕创建匹配,直接创建自动匹配(不是问题)和表格视图,加载localPlayer的游戏中心朋友的邀请。由于现在可以使用playerID填充playersToInvite属性,因此可以在iOS 6中使用。

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

推荐答案

你完成了创建邀请所需的全部工作;你只需要用这段代码发送它:

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

这篇关于GKMatchRequest邀请未在其他设备中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆