I need my app to be compatible both on iPad and iPhone. Its having a tabbarController as the rootViewController.
In iPad I need it to be available both on Landscape and Portrait. In iPhone though I need the rootView to be Portrait itself and i do have some viewsControllers, which are being presented on the tabbarController, which need to be available both in landscape and Portrait (e.g. a viewController used to play videos from Youtube). So I am locking the rotation of the tabbarController as follows (In the UITabbarController Subclass).
# pragma mark - UIRotation Methods
- (BOOL)shouldAutorotate{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
- (NSUInteger)supportedInterfaceOrientations{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait;
}
What I intend to do is that by locking the rotation of the rootviewController(tabbarController), I am locking all the VC's in the tabbarController(only on iPhone) and views which are presented on top of the tabbarController can rotate as per the device orientation.
THE PROBLEM
Everything works as expected until the app is launched in the landscape in the iPhone. When launched in the landscape mode the app defaults to landscape and launches the app in the landscape mode which is not intended. It should launch in the Portrait mode itself even if the device orientation is Landscape. Since I am turning off auto rotation for iPhone the app continues to be in landscape itself resulting in a bug. I tried this method to force the app to launch in portrait in the application:didFinishLaunchingWithOptions:
#pragma mark - Rotation Lock (iPhone)
- (void)configurePortraitOnlyIfDeviceIsiPhone{
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
}
Still the issue persists. I have allowed all orientation options on the info.plist for SupportedInterfaceOrientaions key both for iPad and iPhone since I need the app to be in landscape for iPhone even if only for a few viewControllers. The issue can be fixed if I can somehow force that app to launch in Portrait orientation even if the device orientation is Landscape. Please correct me if am wrong in the logic, if not, any help to make the app launch in the portrait mode will be appreciated.
I have already gone through this question here and here, but couldn't get it working yet.
Thank You