IPhone how do display Leaderboard screen in my own

2019-08-12 04:51发布

i want to show leaderbord in my own game ....i am using following method for that but noting happen ... i am confuse with rootview controller as my game is developed in cocos2d so there is nothing like dat :(

// Leaderboards

-(void) showLeaderboard
{
    if (isGameCenterAvailable == NO)
        return;

    GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
    if (leaderboardVC != nil)
    {
        leaderboardVC.leaderboardDelegate = self;
        [self presentViewController:leaderboardVC];
    }
}
///
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController*)viewController
{
    [self dismissModalViewController];
    [delegate onLeaderboardViewDismissed];
}

///////

-(UIViewController*) getRootViewController
{
    return [UIApplication sharedApplication].keyWindow.rootViewController;
}
///
-(void) presentViewController:(UIViewController*)vc
{
    UIViewController* rootVC = [self getRootViewController];
    [rootVC presentModalViewController:vc animated:YES];
}

////
-(void) dismissModalViewController
{
    UIViewController* rootVC = [self getRootViewController];
    [rootVC dismissModalViewControllerAnimated:YES];
}

... regards

Haseeb

2条回答
Emotional °昔
2楼-- · 2019-08-12 05:17

If you don't have a root UIViewController then I'd recommend creating a new UIViewController set it's view to your openGLView then use that view controller to present the leaderboard as a modal view controller.

UIViewController *leaderboardViewController = [[UIViewController alloc] init];
[leaderboardViewController setView:[[CCDirector sharedDirector] openGLView]];

[leaderboardViewController presentModalViewController:leaderboardVC animated:YES]; //leaderboardVC is your GKLeaderboardViewController
查看更多
Viruses.
3楼-- · 2019-08-12 05:26

i dont know but it work for me.if anyone can describe the real reason for why this working in this way i will be very glad....i call it through appdelegate

[(myAppDelegate*)[[UIApplication sharedApplication] delegate]gameCenter];

and from appdelegate i call rootviewcontroller method like

-(void)gameCenter
{
    [rootViewController gameCenterLeaderboard];
}

and in rootviewcontroller there is a method

-(void)gameCenterLeaderboard
{

    GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
    if (leaderboardVC != nil) {

        leaderboardVC.leaderboardDelegate = self; 
        [self presentModalViewController: leaderboardVC animated: YES];


    }

}

the following method is also override in rootviewcontroller

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardController
{

    [self dismissModalViewControllerAnimated:YES];
}
查看更多
登录 后发表回答