4

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

1 に答える 1

23

GKGameCenterViewControlleriOS 7 では、リーダーボード、実績などのコントローラーがクラスにまとめられています。パラメータを使用して、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);
            }
        }];
    }
}
于 2013-10-02T17:36:49.767 に答える