游戏中心被邀请了

时间:2016-01-22 13:03:37

标签: ios cocos2d-x game-center game-development

我正在为cocos2dx开发iOS游戏,我已整合了Game Center但是当我向朋友发送邀请时,发件人没有收到接收方接受请求的响应,或者没有委托方法正在调用。我已经尝试了所有的解决方案,但没有什么工作进一步我可以分享代码,如果它有任何问题:

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

request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response)
{
    if (response == GKInviteeResponseAccepted)
    {
        NSLog(@"DEBUG: Player Accepted: %@", playerID);
        // Tell the infrastructure we are don matching and will start using the match
    }
};

[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch* match, NSError *error) {
    if (error)
    {
        //Invite has not been sent

          NSLog(@"Invitation has not been sent");
    }
    else if (match != nil)
    {
        //whatever you want to do when the receiver accepts the invite
        NSLog(@"Invitation has  been sent with match object = %@",match);

    }
}];
request.recipientResponseHandler= ^(GKPlayer *player, GKInviteeResponse response)
{


    switch (response) {
        case GKInviteeResponseAccepted:
        {
        }
            break;
        case GKInviteeResponseDeclined:
        {

        }
            break;
        case GKInviteeResponseFailed:
        {

        }
            break;
        case GKInviteeResponseIncompatible:
        {

        }
            break;
        case GKInviteeResponseUnableToConnect:
        {


        }
            break;
        case GKInviteeResponseNoAnswer:
        {


        }
            break;

        default:
            break;
    }

};

GKMatchmakerViewController *mmvc =
    [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.matchmakerDelegate = self;

[viewController presentViewController:mmvc animated:YES completion:nil];

1 个答案:

答案 0 :(得分:0)

这不是一个真正的解决方案,但它是一种解决方法。在我的情况下,我最多有4个玩家,最少2个。如果我向1个玩家发送邀请并让其他2个插槽打开让Apple随机填充,它将永远不会继续。我发现推动事情的唯一方法是在发送邀请之前通过在空插槽上点击X来移除打开的插槽。