20

When Game center is loaded its default orientation is portrait. In order to lock it in landscape mode, added a category.

@implementation GKMatchmakerViewController (LandscapeOnly)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return NO;
}
@end

It is working fine in below iOS 6 .But in iOS6 it shows an error.

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

Please explain a solution.

QCG
  • 2,569
  • 3
  • 20
  • 25

2 Answers2

39

At last i avoided crash by following the workaround mentioned in Apple's iOS 6 release notes.

Workaround:

1.Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}

2. When a UIBNavigationController (or a UIViewController) is involved, subclass the UINavigationController/UIViewController and overriding supportedInterfaceOrientations.

 - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }

And

In buid summary supported orientations selected landscape right and landscape left.

Now game center is working properly without crash.

Steph Thirion
  • 9,313
  • 9
  • 50
  • 58
QCG
  • 2,569
  • 3
  • 20
  • 25
  • Thanks! My ass was saved too :) – Oren Bengigi Oct 08 '12 at 10:45
  • 1
    Worked for me too, but in my case I wasn't using a UIBNavigationController but a UIViewController (its subclass), yet I still had to add method number 2 into it. You might want to replace UIBNavigationController with UIViewController in this answer. – Steph Thirion Dec 16 '12 at 00:59
  • I added that information. Your answer is now more accurate than Apple's release notes. ;) – Steph Thirion Dec 16 '12 at 01:12
  • 1
    it works but my app now supports portrait, how will I stop it from going to portrait. PLease help :( – Arnlee Vizcayno Jan 15 '13 at 14:53
  • Just a small comment: it's more elegant to include just a category attaching to NavigationController class in the Appdelegate then making a new subclass, but it's a working solution in any way. – BootMaker Jun 27 '13 at 11:25
0

Have to add 1 little thing. Struggling with that stupid issue about 2 days. If above doesn't help and you have UINavigationController invovled (and you already did subclass it) you need the following (in appDelegate):

[window setRootViewController:navigationController]; // use this
// instead of [self.window addSubview:navigationController.view];

thanx 2 http://grembe.wordpress.com/2012/09/19/here-is-what-i/

Stan
  • 6,511
  • 8
  • 55
  • 87