Search code examples
iosxcodedevice-orientationmobfox

Allow Landscape and Portrait but force app to remain in Portrait - iOS


I have an app that is designed to run in portrait and all is well. However I have implemented Mobfox's vAds which require landscape mode.

At present I get the following error when the vAD is called

2013-01-08 23:44:05.109 Tv - IOS[1422:907] mobfox video did load
2013-01-08 23:44:05.125 Tv - IOS[1422:907] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

So the im thinking the fix would be allow for landscape in the app.

I need to force the app to run in portrait but allow for landscape when the vAd is called

So just to recap:

I need Portrait only orientation during normal app view and landscape/portrait during the mobFox vAd view is visible.


Solution

  • Return NO for shouldAutorotate:

    -(BOOL)shouldAutorotate {
      return NO;
    }
    

    Or if it is YES you need to return the supportedInterfaceOrientations (at least one), here its only allowing portrait:

    - (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskPortrait;
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
          return UIInterfaceOrientationMaskAll;
      }
    }