iOS7中我应该使用什么而不是弃用的GKLeaderboardV

iOS7中我应该使用什么而不是弃用的GKLeaderboardV

本文介绍了在iOS7中我应该使用什么而不是弃用的GKLeaderboardViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的IOS 7应用程序,游戏中心有一些不赞成的东西,如加载和解雇排行榜和成就我如何解决它说GKLeaderboardViewController已被弃用

ive updated my app for IOS 7 and game center has a few things deprecated such as loading and dismissing the leaderboard and achievements how can i fix them it says GKLeaderboardViewController is deprecated

- (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);
}
}


推荐答案

iOS 7将排行榜,成就等控制器组合到类。您可以使用参数,用于控制要显示的视图。

iOS 7 combines the leaderboards, achievements, etc. controllers together into the GKGameCenterViewController class. You use the viewState parameter to control which view you want displayed.

你想要做这样的事情提出/解除排行榜:

You'll want to do something like this to present/dismiss the leaderboards:

- (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];
}

同样,为了展示成就,你可以这样做:

Similarly, for presenting achievements, you can do this:

- (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);
            }
        }];
    }
}

这篇关于在iOS7中我应该使用什么而不是弃用的GKLeaderboardViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:14