以下代码在iOS 6.0(模拟器和设备)上运行良好。游戏中心很好。但它在iOS 5.0模拟器上没有任何作用。不幸的是我没有iOS 5.0的设备,所以我无法检查它是否是与模拟器相关的问题。
- (void)showLeaderboard:(NSString *)leaderboard
{
GKLeaderboardViewController * leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[leaderboardViewController setCategory:leaderboard];
[leaderboardViewController setLeaderboardDelegate:self];
[[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:leaderboardViewController animated:YES completion:^{
}];
[leaderboardViewController release];
}
那会发生什么?没有。没有提供任何观点。它不会将任何消息记录到控制台中。它甚至没有达到完成块。
我试着玩,这是我设法弄清楚的。我使用继承自GKLeaderboardViewController
而不是纯GKLeaderboardViewController
的CustomLeaderboardViewController,并在shouldAutorotateToInterfaceOrientation方法中放置一个断点。它不会触发上面的代码。但是,如果我使用
setCategory:nil
代替
setCategory:leaderboard
然后那个断点开火了。仍然没有任何进一步发生,并且没有调用完成块。
有什么想法会发生这样的事情吗?
答案 0 :(得分:0)
事实证明这只是一个愚蠢的错误。 [[UIApplication sharedApplication]委托] .window.rootViewController是nil,因为在iOS 5.0的情况下它从未设置过。
答案 1 :(得分:0)
确保您的所有变量(例如'leaderboard')都不是nil,因为Objective C喜欢在这种情况下无声地失败。