IOS 6 orientation issue in universal app

ios5, ios6, ipad, iphone, uiinterfaceorientation

Solution

Is your rootviewcontroller a UINavigation controller or UITabbarcontroller?? If so these methods wont work if you are calling these methods in your view controller.

So create an objective C category on these container view controllers and add to your project.

@implementation UINavigationController (autorotate)


 -(NSUInteger)supportedInterfaceOrientations
 {
   //make the check for iphone/ipad here

if(IPHONE)
    {
return UIInterfaceOrientationMaskPortrait;
    } 
else
    {
return UIInterfaceOrientationMaskLandscape;
    }

 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
return UIInterfaceOrientationPortrait;
 }

 - (BOOL)shouldAutorotate
 {
return NO;
 }

Problem

In my universal app i need to handle different orientation for iphone and ipad. For ipad i need to allow landscape orientation and for iphone portrait alone. I have returned below code at first ``` - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) return UIInterfaceOrientationIsPortrait(interfaceOrientation); return UIInterfaceOrientationIsLandscape(interfaceOrientation); } ``` is working fine in IOS 5 But in IOS 6 autorotate method is not at all fired. After that i have changed the method to, ``` -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; } ``` even this methods are not at all fired in IOS 6. My plist setting is i need to handle both orientation [iPhone-portrait,iPad-landscape] for both IOS 5 and IOS 6. Please guide me to fix this issue.

Original source

Related problems