简体   繁体   中英

game center not working on ipod/iphone

Hi all Working on a universal build for an iphone/ipod/ipad app. I was trying to get game center working within this app. I now have the game center working on the ipad but for some reason it still wont work on the ipod/iphone and i have no idea why.

highScoreVC=[[UIViewController alloc] init];

    GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
    if (leaderboardController != nil)
    {
        leaderboardController.leaderboardDelegate = self;
        [[[CCDirector sharedDirector] openGLView] addSubview:highScoreVC.view];
        [highScoreVC presentModalViewController:leaderboardController animated: YES];
    }

this is my code for displaying the leaderboard and it does work everytime for ipad but as i said not for other devices. the code is still being called the same as for ipad so i have no clue why it is not displaying. any ideas why this would be? cheers

As far as I'm concerned, [GKLeaderboardViewController init] will return nil if the device is not authenticated with Game Center by that point. Are you sure you are correctly authenticated on the devices causing problems?

I suspect there may be some issues with how your UIKit items for Game Center are being displayed if they are working fine on the iPad but not iPhone/iPod. I experienced similar sounding issues when converting an app to universal.

If you create a new standalone iPhone/iPod project just for testing does game center display fine?

ok i got it working in the end. cocos2d 0.99.5 has indeed made some changes that to how this works. the following code displays the leaderboard correctly

-(UIViewController*) getRootViewController{
return (UIViewController*)([(BubbleDreamsAppDelegate*) [[UIApplication sharedApplication] delegate] viewController]);

}

and then

highScoreVC = [self getRootViewController];


    GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];

    if (leaderboardController != nil)
    {
        leaderboardController.leaderboardDelegate = self;

        [highScoreVC presentModalViewController:leaderboardController animated: YES];


    }

hope this helps anyone that gets stuck with same problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM