UIAlertView crashs in iOS 8.3

不羁的心 提交于 2019-12-18 04:02:10

问题


recently i start receiving crash reports for UIAlertView only by users that use iOS 8.3

Crashlytics reports:

Fatal Exception: UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application, and [_UIAlertShimPresentingViewController shouldAutorotate] is returning YES

The line where that crash happens is [alertView show] :

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle
                                          otherButtonTitles:nil];
[alertView show];

that code is in the app for a long time and now it starts crashing. Did anyone experience a similar behaviour and has fixed the problem?


回答1:


try by implementing this

- (BOOL)shouldAutorotate {
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

check this also : Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone




回答2:


The main thing is :

UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application

It means you have somewhere implemented

- (NSUInteger)supportedInterfaceOrientations {

    return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0

In that function MUST be returned Mask like:

UIInterfaceOrientationMaskPortrait which is 1




回答3:


Better than this you should start using UIAlertController. It has much better functionality and also for UIAlertAction you don't have to include delegate methods.

UIAlertController * alert=   [UIAlertController
                             alertControllerWithTitle:@"Info"
                             message:@"You are using UIAlertController"
                             preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction
                    actionWithTitle:@"OK"
                    style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction * action)
                    {
                        [alert dismissViewControllerAnimated:YES completion:nil];

                    }];

UIAlertAction* cancel = [UIAlertAction
                        actionWithTitle:@"Cancel"
                       style:UIAlertActionStyleDefault
                       handler:^(UIAlertAction * action)
                       {
                           [alert dismissViewControllerAnimated:YES completion:nil];

                       }];

[alert addAction:ok];

[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:nil];



回答4:


Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert.

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html




回答5:


After trying the solutions here, none of them worked for me. I'm supporting iOS 6-8 in an app, and, more than that, use some libraries that use UIAlertView internally, so simply conditionally compiling to use UIAlertController when available was not an option.

I came up with a solution that solved the problem for me. Your mileage may vary. I include the header file in the Header Prefix file so that it's sure to be included anywhere a UIAlertView is shown.

I'm posting this here for anyone who's stumbling on this problem and the solutions found around the net don't work. Hopefully it's helpful.

https://gist.github.com/joshhudnall/cdc89b61d0a545c85d1d




回答6:


I created a helper for displaying UIAlertView when before iOS8 and UIAlertController after iOS8, this solves the rotation crash and also displays nicely in all versions.

https://github.com/dannyshmueli/DSAlertDisplayer



来源:https://stackoverflow.com/questions/29534105/uialertview-crashs-in-ios-8-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!