开发者

IPhone - Game Center's choose Leaderboard screen - how can it be displayed?

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 leaderb开发者_JS百科oard 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
  • A particular category's view controller is automatically on top of leaderboard view controller's navigation stack
  • Before display, you can already modify the navigation stack
  • By not animating, popping occurs instantly, and before the view controller is even presented.

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.


Starting from iOS 6.0 you should do it like this:

-(void)showLeaderboards
{
    GKGameCenterViewController *viewController = [GKGameCenterViewController new];
    viewController.viewState = GKGameCenterViewControllerStateLeaderboards;
    viewController.gameCenterDelegate = self;
    [self presentViewController:viewController animated:YES completion:nil];
}

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)viewController
{
    [viewController dismissViewControllerAnimated:YES completion:nil];
}


Got an answer from apple that this feature is not available currently.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜