Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Error: Supported orientations has no common orientation with the application (iPhone)

Using iOS 8.3

I have a view in landscape mode, and i'm trying to open a portrait only view controller. every time i try to open it, the app crashes.

I have read this official apple answer which basically recommends doing the following:

in the app delegate:

@implementation AppDelegate

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
} 

and in my controller:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

And so i have, and yet i still get this crash message:

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

In the project general settings i have the following (which should not be changed according to apple's answer):

settings

I can see that these functions are in fact being called but nothing helps. Any thoughts?

Some questions i read earlier:

How to force a UIViewController to Portrait orientation in iOS 6

iOS6: supportedInterfaceOrientations not working (is invoked but the interface still rotates)

Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

like image 780
Itzik984 Avatar asked Aug 23 '15 17:08

Itzik984


1 Answers

Synopsis: application(_:, supportedInterfaceOrientationsForWindow) -> Int does overwrite the General > Deployment Info. So you can ignore that .plist entirely once you provide supportedInterfaceOrientationsForWindow in the app delegate. See note about UIInterfaceOrientationMaskPortrait.

Having tried the code above every which way, in both Obj-C and Swift, the only times I get...

'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [ViewController shouldAutorotate] is returning YES'

...is when:

  1. using UIInterfaceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait (mask is the keyword here)
  2. or supportedInterfaceOrientations returns a mask not listed in supportedInterfaceOrientationsForWindow

A. Place this block in the the class adopting the UIApplicationDelegate protocol (typically AppDelegate.m or AppDelegate.swift):

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
} 

supportedInterfaceOrientations will overwrite the Deployment Info and allow to dynamically differentiate iPhone from iPad at runtime.


B. Place this block in the UIViewController subclass for which you want a specific behavior (typically CustomViewController.m or CustomViewController.swift):

Obj-C

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Swift

override func supportedInterfaceOrientations() -> Int {
    let supported = UIInterfaceOrientationMask.Portrait.rawValue
    return Int(supported)
}

Tested iOS 8.4

like image 116
SwiftArchitect Avatar answered Nov 14 '22 23:11

SwiftArchitect