Hi all,
I've been trying to let the user launch the Game Center leaderboards for a little while now (just under three hours), and I've been completely unsuccessful. I currently have OpenFeint 2.7.5 implemented, and I have Game Center enabled within it. I am now trying to open the GKLeaderboardViewController to no avail. Code as it stands:
// RootViewController.h
#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
@interface RootViewController : UIViewController <GKLeaderboardViewControllerDelegate> {
UIViewController *tempVC;
}
-(void) showLeaderboard;
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController;
@end
// RootViewController.m
#import "cocos2d.h"
#import "RootViewController.h"
#import "GameConfig.h"
#import "OpenFeint.h"
#import <GameKit/GameKit.h>
@implementation RootViewController
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
#if GAME_AUTOROTATION==kGameAutorotationNone
return NO;
#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
[[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
} else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
}
return NO;
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
const unsigned int numOrientations = 2;
UIInterfaceOrientation myOrientations[numOrientations] = {
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
};
return [OpenFeint
shouldAutorotateToInterfaceOrientation:interfaceOrientation
withSupportedOrientations:myOrientations
andCount:numOrientations];
return NO;
#else
#error Unknown value in GAME_AUTOROTATION
#endif // GAME_AUTOROTATION
return NO;
}
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect;
rect = CGRectMake(0, 0, 0, 0);
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
rect = screenRect;
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [director openGLView];
float contentScaleFactor = [director contentScaleFactor];
if(contentScaleFactor != 1) {
rect.size.width *= contentScaleFactor;
rect.size.height *= contentScaleFactor;
}
glView.frame = rect;
[OpenFeint setDashboardOrientation: toInterfaceOrientation];
}
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
-(void) authenticateLocalPlayer {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if(error == nil) {
// Insert code here to handle a successful authentication.
NSLog(@"Game Center: Player Authenticated!");
} else {
// Your application can process the error parameter to report the error to the player.
NSLog(@"Game Center: Authentication Failed!");
}
}];
}
-(void) showLeaderboard {
[self authenticateLocalPlayer];
tempVC = [[UIViewController alloc] init] ;
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if(leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
[tempVC presentModalViewController:leaderboardController animated:YES];
}
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];
[tempVC release];
}
-(void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void) viewDidUnload {
[super viewDidUnload];
[tempVC release];
}
-(void) dealloc {
[super dealloc];
}
@end
The current problem is that when I call [[RootViewController alloc] showLeaderboard] from my Main Menu Scene, it logs the player authenticated success message, and I have checked that it also adds the view and what not. Despite all this, nothing happens on the game. No leaderboard screen appears. It's like I never clicked anything...
Any ideas?