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

旧城冷巷雨未停 提交于 2019-12-23 01:58:28

问题


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!!


回答1:


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.




回答2:


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];
}



回答3:


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



来源:https://stackoverflow.com/questions/4534308/iphone-game-centers-choose-leaderboard-screen-how-can-it-be-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!