iOS Error: Supported orientations has no common orientation with the application (iPhone)
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:
- using
UIInterfaceOrientationPortrait
instead ofUIInterfaceOrientationMaskPortrait
(mask is the keyword here) - or
supportedInterfaceOrientations
returns a mask not listed insupportedInterfaceOrientationsForWindow
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
Itzik984
Updated on June 23, 2022Comments
-
Itzik984 almost 2 years
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):
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)
-
Itzik984 over 8 yearsNicely explained, The problem was that i did not place the relevant chunk of code in the appDelegate.cpp and placed it in the image picker delegate, that's why it did not work. would you like to edit your answer so that i could accept it? (with the emphasis of placing the chunk of code in the appDelegate class ofc)