Summary: application(_:, supportedInterfaceOrientationsForWindow) -> Int overwrites General> Deployment Information. This way you can ignore this .plist completely once you provide the supportedInterfaceOrientationsForWindow in the application delegate. See Note to UIInterfaceOrientationMaskPortrait .
Having tried the code above each method, both in Obj-C and Swift, only the time I get ...
'UIApplicationInvalidInterfaceOrientation', reason: "Supported orientations do not have a common orientation with the application, and [ViewController shouldAutorotate] returns YES '
... is when:
- using
UIInterfaceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait ( mask is the keyword here) - or
supportedInterfaceOrientations returns the mask not specified in supportedInterfaceOrientationsForWindow
A. Place this block in the class using the UIApplicationDelegate protocol (usually AppDelegate.m or AppDelegate.swift ):
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) return UIInterfaceOrientationMaskAll; else return UIInterfaceOrientationMaskAllButUpsideDown; }
supportedInterfaceOrientations overwrites deployment information and dynamically distinguishes iPhone from iPad at run time.
B. Place this block in a subclass of UIViewController that requires a specific behavior (usually 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
source share