I'm having trouble getting the leaderboards to show up in my game, short of my initial login, i have no idea if gamecenter is cooperating with my code. I prompt the leaderboards using a touch detect on some text, ala... and... Which then triggers... The app simply crashes. It seems as though the app crashes when executing "presentModalViewController", which looks like a function of UIKit? The apple provided GKTapper code doesn't shed any light on how to properly implement this into a CCLayer. Can anyone help? Or is there an existing example other than GKTapper?
I think you are missing the leaderboardViewControllerDidFinish: method. One implementation (that I haven't checked) could be the following, although I had found one-liners as well: -(void)leaderboardViewControllerDidFinishGKLeaderboardViewController*)viewController{ CGRect frame = viewController.view.frame; [UIView beginAnimations"curldoup" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:.5]; [UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context]; frame.origin.y = 480; viewController.view.frame = frame; [UIView commitAnimations]; }
My guess would be that you are just missing the required delegate template in the .h header: Code: @interface MyVC : UIViewController [B]<GKLeaderboardViewControllerDelegate>[/B] { } This delegate is required in any class that you assign to .leaderboardDelegate.
You can't pop a UIViewController directly from a CCLayer, you need to do it from within the context of another UIViewController. First, expose your RootViewController as a property from your AppDelegate: @property (nonatomic, retain) RootViewController *viewController; Then, import your AppDelegate in your CCLayer.h file. Next: GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init]; leaderboardController.leaderboardDelegate = self; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; RootViewController *vCont = appDelegate.viewController; [vCont presentModalViewController:leaderboardController animated:YES]; [leaderboardController release];
Correct. It's just like popping a modal view controller in UIKit. There are a number of people who have written sample code for this and suggest using a temporary view controller, but I prefer to do this against my app's root view controller as that seems to yield better results when dealing with orientation changes.
I had very similar issue, but I found a simple solution, like this: HighscoreScene.h: Code: @interface HighscoreScene : [U]BaseScene[/U] [B]<GKLeaderboardViewControllerDelegate>[/B] { [I](...)[/I] } [I](...)[/I] - (void) [B]showLeaderboard[/B]; - (void) [B]leaderboardViewControllerDidFinish[/B]:(GKLeaderboardViewController *)leaderboardVC; [I](...)[/I] (where BaseScene inherits from NSObject) HighscoreScene.m: Code: - (void) [B]showLeaderboard[/B] { UIWindow* window = [UIApplication sharedApplication].keyWindow; GKLeaderboardViewController *leaderboardVC = [[GKLeaderboardViewController alloc] init]; if (leaderboardVC != nil) { leaderboardVC.leaderboardDelegate = self; UIViewController *vc = [[UIViewController alloc] init]; [window addSubview: vc.view]; [vc presentModalViewController: leaderboardVC animated: YES]; } } - (void)[B]leaderboardViewControllerDidFinish[/B]:(GKLeaderboardViewController *)leaderboardVC { [leaderboardVC dismissModalViewControllerAnimated:YES]; [leaderboardVC.view.superview removeFromSuperview]; [leaderboardVC release]; } -=Agnes=-