在 iOS7 中,我应该使用啥来代替已弃用的 GKLeaderboardViewController?

Posted

技术标签:

【中文标题】在 iOS7 中,我应该使用啥来代替已弃用的 GKLeaderboardViewController?【英文标题】:What should I use instead of deprecated GKLeaderboardViewController in iOS7?在 iOS7 中,我应该使用什么来代替已弃用的 GKLeaderboardViewController? 【发布时间】:2013-10-02 17:18:44 【问题描述】:

我为 ios 7 更新了我的应用程序,并且游戏中心有一些已弃用的内容,例如加载和关闭排行榜和成就,我该如何修复它们,它说 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);


【问题讨论】:

【参考方案1】:

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

【讨论】:

嗨,格雷格,我编辑了这个问题,因为我错过了报告分数部分,我将如何解决这个问题? 我将如何触发 void 声明,因为我希望它在游戏结束时以及他们提交分数时触发 你的意思是如何调用reportHighScore:forLeaderboardId:方法?这类似于您在上面写的这一行:[self.gameCenterManager reportScore: counter forCategory: self.currentLeaderBoard];。相反,你会做类似 [self reportHighScore:counter forLeaderboardId:self.currentLeaderBoard];. 你先生是个美男子,我为你鼓掌,并送你一个虚拟 Hi5 @Greg 什么是高分

以上是关于在 iOS7 中,我应该使用啥来代替已弃用的 GKLeaderboardViewController?的主要内容,如果未能解决你的问题,请参考以下文章

GUITexture 已弃用,那么我应该使用啥来代替它?

jQuery.type() 已弃用。检查 var 是不是不是对象时,我应该使用啥来代替? [复制]

BaseJQueryEventObject、JQueryEventObject 等已弃用。我们用啥来代替它?

在iOS 7中替换已弃用的sizeWithFont:

我应该如何在 Android 中使用/不使用已弃用的方法

我应该使用啥标签而不是 html 中已弃用的标签字体(不能使用 CSS)