iOS 6
提供了新的视图控制器来显示游戏中心信息:GKGameCenterViewController
。
iOS 5.1
是否提供类似的内容(except separate controllers for Leader-board and Achievements)
?
答案 0 :(得分:0)
以下是我在应用程序中处理新旧GameCenter API的方法,它支持iOS 4和7之间的所有内容。
我从GameCenterManager.m示例代码开始。
1)在GameCenterManager.m中,我更改了authenticateLocalUser
- (void) authenticateLocalUser
{
if([GKLocalPlayer localPlayer].authenticated == NO)
{
if ([[GKLocalPlayer localPlayer] respondsToSelector: @selector(setAuthenticateHandler:)]) {
[[GKLocalPlayer localPlayer] setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
[self callDelegateOnMainThread: @selector(processGameCenterAuth:error:) withArg: viewcontroller error: error];
})];
} else {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
[self callDelegateOnMainThread: @selector(processOldGameCenterAuth:) error: error];
}];
}
}
}
2)然后在我的主视图控制器中,这是我的两个版本的身份验证处理程序。
- (void) processOldGameCenterAuth: (NSError*) error; {
// for iOS < 6.0 without the viewcontroller parameter
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (localPlayer.isAuthenticated) {
usingGamecenter = TRUE;
[self.gameCenterManager reloadHighScoresForCategory: kOverallLeaderboard];
} else {
usingGamecenter = FALSE;
}
// *** this is where you update your UI after game center login
}
- (void) processGameCenterAuth: (UIViewController*) gameCenterController error: (NSError*) error; {
if (gameCenterController) {
[self presentViewController:gameCenterController animated:YES completion:nil];
} else {
[self processOldGameCenterAuth: error];
}
}