我正在为iOS
开发cocos2dx
游戏,我已经集成了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];
这不是真正的解决方案,但它是一种解决方法。 就我而言,我最多有 4 名玩家,最少 2 名。 如果我向 1 名玩家发送邀请,并将其他 2 个插槽留给 Apple 随机填充,它将永远不会继续。 我发现推动事情进行的唯一方法是在发送邀请之前通过在空插槽上按 X 来删除开放插槽。