0
votes

I am working on a app in which I am using only one orientation which is Portrait. This is device orientation setting:

enter image description here

But In my app there is Video player (Custom Player of MPMoviePlayerViewController) which I wanted to show in Landscape Right mode only and It should not be rotated. This is working fine, I mean this Custom Player is showing in Landscape Right perfectly, but when I am using an UIAlertview then application is crashed on this method:

- (BOOL)shouldAutorotate {


    return NO;

}

These are some other orientation methods :

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight; // or Right of course
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    return UIInterfaceOrientationMaskLandscape;
}

I am getting this Error:

 *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES'
3

3 Answers

0
votes

iOS8 :UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end
0
votes

iHTCboy's answer fixed it for me after converting to swift.

In swift 4:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}
-1
votes

Solution 1. Go to info.plist and delete the other orientations which you don't need :-

enter image description here Solution 2. Use following code(where your) :-

-(NSUInteger)supportedInterfaceOrientations {
    UIViewController *vC = self.topViewController;
    return vC.supportedInterfaceOrientations;
}

-(BOOL)shouldAutorotate {
   UIViewController *vC = self.topViewController;
   return [vC shouldAutorotate];
}