由于iOS 6中GameKit API的更新,我终于能够按照它应该的方式实现我的回合制棋盘游戏,完成转换超时和更好的程序化匹配创建。但是,我遇到了一个我似乎无法解决的问题。我的愿望是让Game Center对最终用户完全不可见,这样一切都是程序化的,并使用我自己的自定义界面。因此,我使用自己的自定义表格视图来显示匹配项,而不是默认的GKTurnBasedMatchmakerViewController。现在,我使用-loadMatchesWithCompletionHandler:方法显示打开的匹配没有问题。我还使用自定义屏幕来创建一个匹配,直接创建自动匹配(而不是问题)和一个表格视图,用于加载localPlayer的Game Center朋友以获得邀请。由于playersToInvite属性现在可以用playerID填充,所以在iOS 6中可以这样做。GKMatchRequest邀请没有在其他设备上显示
我的主要问题是在收件人一方处理邀请。我使用以下代码发送邀请
-(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");
}
为什么通知不发呢,还是没有收到通知的推出?是否有另一种方式来发送通知,邀请玩游戏? 我检查了我的沙箱帐户的游戏中心允许邀请,我不知道发生了什么
为什么你使用'.inviteHandler',如果它不赞成iOS 7?如何通过另一种方式获得'GKInvite * acceptedInvite'? – 2014-01-14 23:09:45