Reputation: 362
This has been asked here before the solution has also been given but doesn't work properly
iOS 6 Game Center Crash on Authentication
Check this I am having the same problem. The above code in the link solved it, GameCenter works but now the the cocos2d game rotates that what creates problem for the game. Has anybody solved it or have any solution for this
Also tried this but it doesn't work GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation as i think because i am using cocos2d scene.
Currently i am implementing this code to solve the problem as i have no other choice.
-(NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
The solution i need is simple to open the gamecenter without crashing while locking the code for the orientation to landscape(keep all cocos2d scenes in landscape) Any Help would be Appreciated. Thank you in Advance.
Upvotes: 2
Views: 1118
Reputation: 2375
I finally got Game Center to work in iOS 6 with locked landscape left for me.
I put this code in my AppDelegate. (not the viewcontroller)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
and I put this in my view controller.m
- (void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
[self presentViewController:viewController animated:YES completion:nil];
}
};
}
I also found the updates for the leaderboard and achievement view controllers.
[self presentViewController:achievements animated:YES completion:nil];
[self presentViewController:leaderboardController animated:YES completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
Upvotes: 2
Reputation: 22559
From my experience, most of the answers I went through solved the issue on cocos2d 1.x. However, my game was developed using cocos2d 2.x, so here is what fixed my problem:
1) I have these settings in the target settings:
People were saying I should add portrait support, but that just screwed up my rotation...
2) Make sure you are using the latest cocos2d 2.x! Even if it is in beta! (Currently v2.1 b2)
http://www.cocos2d-iphone.org/
Trust me, I have had many errors and headaches because I thought beta was unstable, and I didn't use it. Ultimately, upgrading to beta is always recommended with cocos2d (unlike Xcode!)
3) In the AppDelegate.m, make sure you are NOT using CCDirector
methods runWithScene:
and pushScene:
inside - (BOOL)application: didFinishLaunchingWithOptions:
What you want to do, is use this function only:
// This is needed for iOS4 and iOS5 in order to ensure
// ... blah blah blah
- (void)directorDidReshapeProjection:(CCDirector *)director {
if (director.runningScene == nil) {
// Add the first scene to the stack. blah blah...
// and add blah
[director runWithScene:[LanguageScene node]];
}
}
And just a speculation, don't authenticate the player in - (BOOL)application: didFinishLaunchingWithOptions:
. Authenticate him after your main scene has been loaded, and onEnterTransitionDidFinish
is called.
Upvotes: 2