Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GKGameCenterViewController always shows Challenges instead of Leaderboards

I'm using Apple's code to show a GKGameCenterViewController:

GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
    gameCenterController.gameCenterDelegate = self;
    [self presentViewController:gameCenterController animated:YES completion:nil];
}

This is the text describing the code above:

Game Center UI is Displayed by Your View Controller (iOS)

The convention used by Game Kit is for one of your view controllers to present the Game Kit view controller. Your view controller acts as a delegate to the view controller it presents so that it can be informed when the player is finished looking at the presented screen. Listing 2-1 shows most common use of this pattern, which is to show the Game Center user interface. The Game Center view controller displays many different pieces of Game Center content, so most games should offer a button that brings the player to this screen, even if the game also shows Game Center content using a custom user interface.

When I use the recommended code I get to this screen (GameCenter Challenges), which is not what I want:

GameCenter Challenges Screen

I have also tried this code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];

By using that code, I get to the screen I expected to display:

enter image description here

Do I misunderstand something or am I doing something wrong? Shouldn't the first piece of code bring me to the main menu? Why won't it show the leaderboards?

UPDATE

I implemented viewState as suggested by phix23:

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

But, it still displays the same Challenges screen, despite the fact that I want /try to display the Leaderboards screen.

like image 247
PeterK Avatar asked Mar 25 '13 22:03

PeterK


1 Answers

The GKGameCenterViewController which is available since iOS 6 can show the leaderboards, achievements and challenges of your game center enabled application.

You can change the initial view by setting the viewState of the GKGameCenterViewController. If you don't set this property it will show the default view, which is the challenges view in your case. I guess you don't have setup any leaderboards or achievements so there is nothing to be shown.

like image 190
Felix Avatar answered Sep 28 '22 05:09

Felix