As I go through apple documentation, I can't see a way to open Game Center where the first screen is the where the user can choose a leaderboard.
I know I can open a specific leaderboard screen , but I want to open the screen that let the user choose one. is that possible ?
This is my code currently:
GKLeaderboardViewController *viewController = [[GKLeaderboardViewController alloc] init];
viewController.leaderboardDelegate = self;
// Present leaderboard with the user's options saved from prevous launch
viewController.category = self.category;
viewController.timeScope = self.timeScope;
[parent presentModalViewController:viewController animated:YES];
Thanks!!
Here's an undocumented workaround, but which was approved in multiple games I worked on:
GKLeaderboardViewController *viewController = [[GKLeaderboardViewController alloc] init];
viewController.leaderboardDelegate = self;
[viewController popViewControllerAnimated:NO];
[parent presentModalViewController:viewController animated:YES];
[viewController release];
Explanation:
GKLeaderboardViewController
is a subclass of UINavigationController
You can skip setting the category and time scope since you don't need them (you won't be displaying a particular "category's" view controller). Even if you don't set it, leaderboard view controller will be pushing default view controller on top.
I have additionally released the viewController
variable (the leaderboard view controller), since parent
view controller will be taking ownership of the object. Not releasing it therefore creates a memory leak and may have other unintended consequences.
iOS 6 and later have the GKGameCenterViewController
class. Weak-link to GameKit and test for presence of this class with NSClassFromString(@"GKGameCenterViewController") != nil
. Then, use it as usual.
Instantiate this class instead of the GKLeaderboardViewController
and set its viewState
property to GKGameCenterViewControllerStateLeaderboards
to have leaderboards show immediately.