GameKit是否允许您以编程方式邀请特定的游戏中心朋友参加比赛,即无需呈现GC ViewController?以下handleInviteFromGameCenter文档似乎暗示您可以填充GKMatchRequest.playersToInvite并将其与[GKTurnBasedMatch findMatchForRequest]一起使用:
当您的委托收到此消息时,您的应用程序应创建一个新的GKMatchRequest对象,并将playersToInvite参数分配给匹配请求的playersToInvite属性 . 然后,您的应用程序可以调用GKTurnBasedMatch类方法findMatchForRequest:withCompletionHandler:以编程方式查找匹配项,也可以使用该请求实例化新的GKTurnBasedMatchmakerViewController以显示该播放器的用户界面 .
但是我发现当findMatchForRequest用填充的匹配调用我的完成块时,传递给它的GameCenter ID不会被设置为第二个玩家 . 相反,它是空的,状态是“匹配” . 因此,当我调用endTurnWithNextParticipant时,它会成功,但我的第二台设备上没有收到邀请 . 这说明了我在做什么:
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = [NSArray arrayWithObjects: otherPlayerGCID,nil ];
[GKTurnBasedMatch findMatchForRequest:request
withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
if (error)
NSLog(@"returned from fimdmatch but with error");
else if (match != nil) {
NSLog(@"match returned success and match populated");
NSArray* otherPlayers = [match participants];
if (otherPlayers.count>1) {
NSData* placeholder = [@"no data" dataUsingEncoding:NSUTF8StringEncoding];
[match endTurnWithNextParticipant:[otherPlayers objectAtIndex:1]
matchData:placeholder
completionHandler:^(NSError *error)
{
if (error)
NSLog(@"returned from END TURN but with error");
else
NSLog(@"returned from END TURN successfully");
}];
}
}
else
System::log("match returned success but match NOT populated");
}];
就像那个似乎有类似问题的人Game Center inviting friends progammatically,如果我插入一个调用视图控制器,在我的情况下GKTurnBasedMatchmakerViewController,一切似乎都有效 .
谢谢 .
更新:我确实在Apple开发者关于回合制GC的演示文稿中看到,提到了类似的事情,“如果你想邀请GC的朋友,我们要求你通过GC视图控制器 .
有任何见解赞赏 . 再次感谢 .
1 回答
想要分享我在这方面所学到的东西:从iOS 5开始,没有办法邀请游戏中心的朋友玩游戏而不经过预定义的GKTurnBasedMatchmakerViewController流程,该流程针对实时开始匹配进行了优化,引导用户通过三个不同的屏幕 .
在被苹果开发支持催促之后,我确实提交了一个功能请求,以便能够调用一个简单的单页视图控制器,允许用户通过游戏中心发送邀请/“推荐游戏”消息 .
UPDATE FOR iOS 6: 很高兴地报告在iOS 6中已经解决了这个问题 . 我上面的原始程序化(非UI)示例现在可以像最初预期的那样工作 .