0

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'
ajeet sharma
  • 803
  • 10
  • 37
  • might be that help: http://stackoverflow.com/questions/29534105/uialertview-crashs-in-ios-8-3 and https://www.google.co.in/search?q=[UIAlertController+shouldAutorotate]+is+returning+YES%27&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=ZxtIV-6uFKfT8geUpoiwDg – Nitin Gohel May 27 '16 at 10:03

3 Answers3

1

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

In swift 4:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Kioja
  • 31
  • 6
0

iOS8 :UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end
iHTCboy
  • 2,715
  • 21
  • 20
-1

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];
}
shubham mishra
  • 971
  • 1
  • 13
  • 32