我已设置好以便我的应用可以连接到游戏中心。我按照this指南编写了一个C ++类包装器,在我的其他类中调用它们。我正在使用iPad(iOS 5.1),iPod Touch第四代(iOS 5.1)以及iPhone 4s和3GS进行测试。它在iPad设备上运行良好但由于某些未知原因,它不适用于iPhone和iPod。它正确地连接到Sandbox但是UI没有显示,或者说UI在屏幕外的某个地方。
iPhone上发生的事情是:
这就是我启动Game Center UI的方式:
- (void)showLeaderboardForCategory:(NSString *)category
{
// Only execute if OS supports Game Center & player is logged in
if ( hasGameCenter )
{
// Create leaderboard view w/ default Game Center style
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
// If view controller was successfully created...
if (leaderboardController != nil)
{
// Leaderboard config
leaderboardController.leaderboardDelegate = self; // The leaderboard view controller will send messages to this object
leaderboardController.category = category; // Set category here
leaderboardController.timeScope = GKLeaderboardTimeScopeToday; // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime
// Create an additional UIViewController to attach the GKLeaderboardViewController to
myViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil ];
// Add the temporary UIViewController to the main OpenGL view
// NOTE: This is the part that I think is the suspect. I am not sure if iPhones and iPods support EAGLView.
[ [ EAGLView sharedEGLView ] addSubview:myViewController.view ];
// Tell UIViewController to present the leaderboard
[ myViewController presentModalViewController:leaderboardController animated:NO ];
NSLog( @"Leaderboard opened." );
}
}
}
任何帮助都表示赞赏,并提前致谢。
编辑:使用OpenFeint不是一种选择。
答案 0 :(得分:2)
试试这个。不要使用'EAGLView'
- (void) showLeaderboard
{
if (!gameCenterAvailable) return;
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
currentModalViewController = [[UIViewController alloc] init];
[window addSubview:currentModalViewController.view];
[currentModalViewController presentModalViewController:leaderboardController animated:YES];
}
}