【发布时间】:2016-04-29 02:15:38
【问题描述】:
我正在为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];
【问题讨论】:
-
你收到任何 GKInviteeResponse 了吗?
标签: ios cocos2d-x game-center game-development