PLEASE READ THIS ATTENTIVELY, or you can lose 1-2 days of your life by losing your mind and fighting, shaking, turning your test device like a chimpanzee into a zoo that grabbed a visitor's mobile! Sooner or later ... promise :)
IN iOS 6
shouldAutorotateToInterfaceOrientation:
deprecated and replaced by
shouldAutorotate
this means that iOS 6 will never call shouldAutorotateToInterfaceOrientation :
so if you used the following in your application
BEFORE iOS6 (iOS5, iOS4, etc.)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationPortrait) {
you should use
AFTER iOS 6+
- (BOOL)shouldAutorotate { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait) {
FAMILIARIZE
UIInterfaceOrientation is a property of UIApplication and contains only 4 features that correspond to the orientation of the status bar:
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
DO NOT SAVE
UIDeviceOrientation , which is a property of the UIDevice class and contains 7 possible values:
UIDeviceOrientationUnknown - Can not be determined UIDeviceOrientationPortrait - Home button facing down UIDeviceOrientationPortraitUpsideDown - Home button facing up UIDeviceOrientationLandscapeLeft - Home button facing right UIDeviceOrientationLandscapeRight - Home button facing left UIDeviceOrientationFaceUp - Device is flat, with screen facing up UIDeviceOrientationFaceDown - Device is flat, with screen facing down
even theoretically, you can use the UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; that returns a UIDeviceOrientation - the actual orientation of the device - BUT you should know that UIDeviceOrientation not always equal to UIInterfaceOrientation !!! For example, when your device is on a simple table, you may get an unexpected value.
You can use UIInterfaceOrientation orientation = self.interfaceOrientation; which returns the UIInterfaceOrientation , the current orientation of the interface, BUT this is a property of the UIViewController , so you can only access this in the UIViewController classes.
If you want to support both previous iOS6 devices (iOS3 / 4/5) and iOS6, which may be obvious, just use both shouldAutorotateToInterfaceOrientation: and shouldAutorotate in your code.
From iOS 6, there are 3 levels and 3 steps that the device checks during the launch of the application, which you must control if you want.
1. Info.plist - Supported Interface Orientations
which you can set graphically on the Summary tab. The sequence of permitted orientations is IMPORTANT, which you can change manually by editing info.plist , and the device will select the first one when the application starts! This is very important because the problem always lies in launching the application when it is likely that [UIDevice currentDevice].orientation unknown, especially when we test our application on a flat surface.

LIMIT There are two more settings with the extension (iPad) or (iPhone), if you use any of them, it will use this setting of the current device or simulator and neglect the general settings without extension. Therefore, if you run the iPhone application only for iPhone, and by chance you leave the line “Supported Interfaces (iPad)” somewhere in the plist even without any data, it will neglect the rules that you set earlier in the general settings (in my example for iPhone), and you may receive a rejection of your application with the text "We found that your application does not meet the requirements for working on the iPad ..." even if your application does not intend to use this orientation on the iPhone, but the iPad use it, which can lead to failure apparent errors, since all iPhone apps must run on the iPad too during the upload process.
2. AppDelegate - application:supportedInterfaceOrientationsForWindow
returns a list of mini masks of all permissions that you want to allow, which override info.plist parameters. This is called at least once every time the device rotates.
3. Top-level view controller or RootViewController - supportedInterfaceOrientations
which gives the intersection with the delegate set of the application and the application, which must have a nonzero result to avoid a failure. This is called at least once every time the device rotates, except that a different method is installed in our controller:
shouldAutorotate
which prevents the application from resolving, and gives BOOL by default YES .
BE CAREFUL when you use `NavigationController`
as the topmost controller in your AppDelegate , for example:
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController]; self.window.rootViewController =nil; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES;
in this case, you should put the following code in your AppDelegate as a category attachment in the NavigationController class, since this is the topmost controller, and if you did not subcategory it, you do not have a place / code where you can set your orientation settings, so you you need to make it check your real rootViewController in this case the detailViewController for orientation:
@implementation UINavigationController (OrientationSettings_IOS6) -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end
after that, you can set your preferred orientations in your "top" ViewController (in my example, it is a detailViewController ) with any of the methods available in iOS 6 for ViewControllers , as shown below:
1. (BOOL)shouldAutorotate 2. (NSUInteger)supportedInterfaceOrientations 3. (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation