2013-10-02 82 views
4

香港專業教育學院更新我的應用程序的IOS 7和遊戲中心已棄用,如裝載和解聘排行榜和成就如何解決他們的幾件事情,它說GKLeaderboardViewController已被棄用我應該使用iOS7中的什麼來代替已棄用的GKLeaderboardViewController?

- (IBAction)LeaderBoardsButton:(id)sender { 
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init]; 
if (leaderboardController != NULL) 
{ 
    leaderboardController.leaderboardDelegate = self; 
    [self presentViewController:leaderboardController animated:YES completion:NULL]; 
} 
{ 
    AudioServicesPlaySystemSound(SoundID); 
} 
} 

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController 
{ 
[self dismissViewControllerAnimated:YES completion:NULL]; 
{ 
    AudioServicesPlaySystemSound(SoundID2); 
} 
} 

- (IBAction)AchievementsButton:(id)sender { 
GKAchievementViewController *achievements = [[GKAchievementViewController 
               alloc] init]; 
if (achievements != nil) 
{ 
    achievements.achievementDelegate = self; 
    [self presentViewController:achievements animated:YES completion:NULL]; 
} 
{ 
    AudioServicesPlaySystemSound(SoundID); 
} 
} 

- (void)achievementViewControllerDidFinish:(GKAchievementViewController 
             *)viewController 
{ 
[self dismissViewControllerAnimated:YES completion:NULL]; 
{ 
    AudioServicesPlaySystemSound(SoundID2); 
} 
} 

我要報告的分數是這樣

- (IBAction)ShareScore:(id)sender { 
[self.gameCenterManager reportScore: counter forCategory: self.currentLeaderBoard]; 

GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init]; 
if (leaderboardController != NULL) 
{ 
    leaderboardController.category = self.currentLeaderBoard; 
    leaderboardController.timeScope = GKLeaderboardTimeScopeToday; 
    leaderboardController.leaderboardDelegate = self; 
    [self presentViewController:leaderboardController animated:YES completion:NULL]; 
} 
{ 
    AudioServicesPlaySystemSound(SoundID); 
} 
} 

回答

23

的iOS 7結合了排行榜,成績等控制器一起放入GKGameCenterViewController類。您可以使用viewState參數來控制要顯示的視圖。

你會想要做這樣的事情來呈現/關閉該排行榜:

- (void) presentLeaderboards { 
    GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init]; 
    gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards; 
    gameCenterController.gameCenterDelegate = self; 
    [self presentViewController:gameCenterController animated:YES completion:nil]; 
} 

- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

同樣,對於展示成就,你可以這樣做:

- (void) presentAchievements { 
    GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init]; 
    gameCenterController.viewState = GKGameCenterViewControllerStateAchievements; 
    gameCenterController.gameCenterDelegate = self; 
    [self presentViewController:gameCenterController animated:YES completion:nil]; 
} 

報告得分看起來會像這樣:

- (void) reportHighScore:(NSInteger) highScore forLeaderboardId:(NSString*) leaderboardId { 
    if ([GKLocalPlayer localPlayer].isAuthenticated) { 
     GKScore* score = [[GKScore alloc] initWithLeaderboardIdentifier:leaderboardId]; 
     score.value = highScore; 
     [GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) { 
      if (error) { 
       NSLog(@"error: %@", error); 
      } 
     }]; 
    } 
} 
+0

嗨格里格工作完美我編輯了問題,因爲我錯過了報告分數部分我將如何解決? – Azabella

+0

我怎麼會觸發無效聲明,因爲我希望在比賽結束就引發,當他們提交有得分 – Azabella

+1

你是說你怎麼罵的reportHighScore:forLeaderboardId:方法?這將類似於你在上面寫的這一行:[self.gameCenterManager reportScore:counter forCategory:self.currentLeaderBoard] ;.相反,你會做一些像[self reportHighScore:counter forLeaderboardId:self.currentLeaderBoard] ;. – Greg

相關問題