0

I have set up my leader board in the Game Center.

How do I make it so when the user clicks the high score button, it takes them right to the specific leader board in the Game Center?

Is there a way to do it without using a specific link in a UIWebView?

I would prefer the Game Center to open outside of the app. My app is tailored for iOS7 and above.

user3614030
  • 481
  • 6
  • 16

1 Answers1

1

Far far ago, under iOS7, U can't control what's happening inside the GKGameCenterViewController, just this 3 options:

typedef NS_ENUM(NSInteger, GKGameCenterViewControllerState) {
    GKGameCenterViewControllerStateDefault = -1,
    GKGameCenterViewControllerStateLeaderboards,
    GKGameCenterViewControllerStateAchievements,
    GKGameCenterViewControllerStateChallenges,
};

U can set this property:

@property (nonatomic, assign)   GKGameCenterViewControllerState viewState;

Like this (an example):

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

From iOS7 and above u have this property (never try it):

@property (nonatomic, retain)   NSString *leaderboardIdentifier __OSX_AVAILABLE_STARTING( __MAC_NA, __IPHONE_7_0); // Showing specified leaderboard

So just set this property, and there u go, u have opened the GKGameCenterViewController with your wanted Leaderboard :)

Good luck!

Edit:

To dismiss the Game Center screen, in your GKGameCenterControllerDelegate add this method:

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
    [gameCenterViewController dismissViewControllerAnimated:YES completion:^{

    }];
}
gran33
  • 12,421
  • 9
  • 48
  • 76
  • Thank you for your answer. I am still a bit confused. I know you said the - (void)presentLeaderboardsOnViewController:(UIViewController *)viewController was for under iOS7 but I tried it and it opened the leaderboard that I wanted it to. However when I went to click the "Done" button, it does not take me back to the app. Is there a way to get around that? – user3614030 Sep 17 '14 at 22:58
  • @property (nonatomic, retain) NSString *leaderboardIdentifier Is the property that available from iOS7 and above. Now, for your question, see my next edit in my answer.. – gran33 Sep 18 '14 at 07:08