Iphone – Game center login lock in landscape only in i OS 6

game-centerios6iphoneuiinterfaceorientation

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.

Best Answer

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.