I have a universal app for iOS 8/9 which contains a MainStoryboard_iPhone and a MainStoryboard_iPad. The entry point in the storyboard is a RootViewController with a Tab Bar. The RootViewController controller is quite simple
- (void)viewDidLoad
{
[(VIBAppDelegate *)[[UIApplication sharedApplication] delegate] setRootViewController:self];
self.interfaceOrientationMask = UIInterfaceOrientationMaskAll;
self.preferredOrientation = UIInterfaceOrientationMaskAll;
[super viewDidLoad];}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return self.interfaceOrientationMask;
}
- (BOOL)shouldAutorotate{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
UIViewController *currentVC = self.selectedViewController;
if ([currentVC respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
UIInterfaceOrientation orientation = [currentVC preferredInterfaceOrientationForPresentation];
return orientation;
}else{
return self.preferredOrientation;
}
}
When I launch this app on an iPhone the supportedInterfaceOrientation and shouldAutorotate methods are called during app startup and whenever the device rotates. When I launch the app on an iPad they are never called. In both cases the viewDidLoad function is called as expected.
I have been puzzling over this for hours. I see no differences in the storyboards other than layout. Both device types allow for all 4 orientations and other relevant keys from the Info.plist file.
<key>UIMainStoryboardFile</key>
<string>MainStoryboard_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>MainStoryboard_iPad</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIStatusBarStyle</key>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Putting breakpoints at the shouldAutorotate function shows that is is being called by UIWindow _shouldAutorotateToInterfaceOrientation:checkForDismissal:is... which is called by UIApplicationMain. This is as expected.
On iOS 9, an iPad app by default opts into iPad multitasking. This means that it must adopt all orientations at all times. Since you have not opted out of iPad multitasking, the runtime assumes that you do adopt all orientations at all times — and thus it doesn't need to bother to ask you what orientations you permit, as it already knows the answer (all of them).