0

I have developed a game in cocos2d and all game screens are in Landscape mode. I am trying to implement game Center but getting crash on authentication. I did not find answer of similar type of issues. please suggest right approach...

Crash issue:-'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

I tried below solution but it also disturb game orientations, game starts work in portrait mode also, that i don't want:-

  • (NSUInteger)application:(UIApplication*)application

    supportedInterfaceOrientationsForWindow: (UIWindow*)window { return UIInterfaceOrientationMaskAllButUpsideDown; }

2 Answers2

2

Make sure you selected landscape in Xcode summary page.

enter image description here

Also add these code in your viewcontroller

-(NSUInteger)supportedInterfaceOrientations {
   return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

Update this function in AppDelegate:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskLandscape;
}
Guru
  • 21,652
  • 10
  • 63
  • 102
  • First of all there is no ViewController in game, It is through navigation controller, 2nd it crashes on game center authentication because all game in landscape and masks also set properly in summary, Please try to implement in ios 6 landscape support only - navController_ = [[UINavigationController alloc] initWithRootViewController:director_]; navController_.navigationBarHidden = YES; // set the Navigation Controller as the root view controller // [window_ addSubview:navController_.view]; // Generates flicker. [window_ setRootViewController:navController_]; – user2067367 Jul 23 '13 at 06:20
  • ok, its cocos2d 2.0, change type landscape in supportedInterfaceOrientationsForWindow, and that never crash in device...only in simulator... – Guru Jul 23 '13 at 06:25
  • Could you please show full function code, what about view controller code ? – user2067367 Jul 23 '13 at 09:18
  • in cocos2d 1.0 only rootviewcontroler is used...in cocos2d 2.0 u can find in AppDelegate...already added. Now crashed fixed in device right ? – Guru Jul 23 '13 at 10:47
  • I had placed below code in appdelegate but sill crashed:- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window { return UIInterfaceOrientationMaskLandscape; } – user2067367 Jul 23 '13 at 12:49
  • :) see my above answer..I already added function for supportedInterfaceOrientationsForWindow – Guru Jul 23 '13 at 12:51
  • but it is still crashing on iPod 5 on game center authentication – user2067367 Jul 23 '13 at 13:38
  • Set all masks on through app target summary and then added code for it and it worked interface MyRootViewController : UINavigationController implementation MyRootViewController -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; // return UIInterfaceOrientationMaskAll; } - (BOOL)shouldAutorotate { return YES; } – user2067367 Jul 24 '13 at 06:00
  • 1
    If I could upvote this answer a million times, I would. My god, I've spent so much time looking into this issue, and there are so many answers that say "You just have to enable Portrait orientation as of iOS 6 if you want Game Center." Clearly, you don't! (Which is great because enabling Portrait for an otherwise Landscape-only game creates a bunch of other issues.) Your answer 100% solved the problem for me. THANK YOU! – Michael Oct 11 '13 at 19:54
0

the solution for that is short, i spent a lot of time before finding it:

in the AppDelegate in the method didFinishLaunchingWithOptions put this line:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

obviously before call the login game center method, i put that before create the UIWindows

busta117
  • 526
  • 4
  • 8