当一个人接受邀请时,gameKit 会调用以下委托方法
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"%@ accepted invite",player.playerID);
RIYGameNavigationController *root = (RIYGameNavigationController*)[[[UIApplication sharedApplication]delegate]window].rootViewController;
[root popToRootViewControllerAnimated:YES];
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithInvite:invite];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}
当用户尚未呈现GKMatchmakerViewController
.
如果邀请进入时用户已经在使用 GKMatchmakerViewController(例如:当用户已经在尝试查找匹配项时),这将不起作用。如果是这种情况,当邀请进入时,我会收到以下警告,并且不会显示带有邀请的控制器(因为已经出现了 matchmakercontroller)。结果,用户无法响应邀请。(什么都没发生)。
Warning: Attempt to present <GKMatchmakerViewController: 0x1458a250> on <RIYGameNavigationController: 0x1461f190> which is already presenting <GKMatchmakerViewController: 0x1465fcb0>
在 iOS6 中,可以通过以下方式解决此问题:
if([topLevelViewController modalViewController] != nil)
[topLevelViewController dismissModalViewControllerAnimated:NO];
然后创建GKMatchmakerViewController
. dismissModalViewControllerAnimated:
在 iOS6 中已被弃用。建议dissmissViewControllerAnimated:completion:
改用,但对我不起作用。这是我尝试过的:
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"%@ accepted invite",player.playerID);
RIYGameNavigationController *root = (RIYGameNavigationController*)[[[UIApplication sharedApplication]delegate]window].rootViewController;
[root popToRootViewControllerAnimated:YES];
if ([[root presentedViewController]class] == [GKMatchmakerViewController class]) {
[root dismissViewControllerAnimated:YES completion:nil];
}
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithInvite:invite];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}
if 块被输入,但现有的 GKMatchmakerViewController 没有被解除,新的也没有出现。如果我在 if 语句中放置一个断点,当我在中断后“继续”时,视图控制器被解除,但新的控制器不会弹出。
我怎样才能得到这个工作?