简体   繁体   中英

Crash on shouldAutorotate() method when UIAlertview show in Landscape viewcontroller?

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

在此处输入图片说明

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'

iOS8 :UIAlertController

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

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

In swift 4:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}

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

在此处输入图片说明 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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM