ios6 - GKMatchRequest 邀请未显示在其他设备中

标签 ios6 game-center gamekit invitation

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

我的主要问题是处理接收方的邀请。我用以下代码发送邀请

-(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");

        }
    };

}

我有一个处理通知的代表。以下代码在用户通过身份验证时启动
-(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");

}

为什么没有发送通知?或者没有收到通知?还有其他方法可以发送通知邀请玩游戏吗?
我查了一下,我的 Game Center 沙盒帐户允许邀请,但我不知道发生了什么

最佳答案

您几乎完成了创建邀请所需的所有工作;你只需要用这个代码发送它:

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

关于ios6 - GKMatchRequest 邀请未显示在其他设备中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16266089/

相关文章:

ios - iPad iOS 6 如何防止顶角 UINavigationBar 与背景图像四舍五入

iphone - 无法将分段控件连接到其 IBOutlet

ios - 禁用键盘时

iOS Game Center 提交 float 而不是 int64_t

iphone - 另一个 View 中的相机预览宽度问题

ios - localPlayer是否仍然通过身份验证,即使身份验证失败

iphone - 如何在 iOS 6 游戏中心启用 Facebook 点赞按钮?

iphone - 游戏中心。如何更改排行榜中显示点的外观?

ios - Game Center 无法识别游戏

iphone - GKTurnBasedParticipant 信息