iOS 8.3中的UIAlertView崩溃

iOS 8.3中的UIAlertView崩溃,ios,objective-c,uialertview,Ios,Objective C,Uialertview,最近,我开始只接收使用iOS 8.3的用户的UIAlertView崩溃报告 Crashlytics报告: 致命异常:UIApplicationInvalidInterfaceOrientation 受支持的方向与应用程序没有共同的方向,[\u UIAlertShimPresentingViewController shouldAutorotate]返回YES 发生崩溃的行是[alertView show]: UIAlertView *alertView = [[UIAlertView alloc

最近,我开始只接收使用iOS 8.3的用户的UIAlertView崩溃报告

Crashlytics报告:

致命异常:UIApplicationInvalidInterfaceOrientation 受支持的方向与应用程序没有共同的方向,[\u UIAlertShimPresentingViewController shouldAutorotate]返回YES

发生崩溃的行是[alertView show]:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle
                                          otherButtonTitles:nil];
[alertView show];
该代码在应用程序中存在很长时间,现在它开始崩溃。是否有人经历过类似的行为并已修复该问题?

重要信息UIAlertView在iOS 8中不受欢迎。(请注意,UIAlertViewDelegate也不推荐使用。)要在iOS 8及更高版本中创建和管理警报,请使用首选样式为UIAlertControllerStyleAlertUIAlertController


比这更好的是,您应该开始使用
UIAlertController
。它具有更好的功能,而且对于
UIAlertAction
来说,您不必包含委托方法

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];

试着实现这个

- (BOOL)shouldAutorotate {
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
同时检查此项:

主要内容是:

UIApplicationInvalidInterfaceOrientation支持的方向与应用程序没有共同的方向

这意味着你已经在某个地方实现了

- (NSUInteger)supportedInterfaceOrientations {

    return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}
UIInterfaceOrientationPortrait=UIDeviceOrientationPortrait=0

在该函数中,必须返回掩码,如下所示:


UIInterfaceOrientation面具肖像是1

在尝试了这里的解决方案后,没有一个对我有效。我在应用程序中支持iOS 6-8,而且,除此之外,还使用一些在内部使用UIAlertView的库,因此,在可用时,只需有条件地编译以使用UIAlertController是不可取的

我想出了一个解决问题的办法。您的里程可能会有所不同。我将头文件包括在头前缀文件中,以便确保它包含在显示UIAlertView的任何位置

我把这篇文章贴在这里是为了那些在这个问题上遇到困难的人,而在网络上找到的解决方案是行不通的。希望这会有帮助


我在iOS8之前和iOS8之后创建了一个用于显示UIAlertView和UIAlertController的助手,这解决了旋转崩溃问题,并且在所有版本中都能很好地显示


它在iOS 8中已被弃用。我知道-但弃用的东西应该仍然有效,并且在iOS 8.0、8.1和8.2中运行良好。由于我的应用程序也支持iOS 7,并且我不想为UIAlertView调用引入条件,因此我决定保留旧代码,只要它支持UIAlertController,我就会收到相同的错误。子类化UIAlertController(或UIAlertView)应该可以解决这个问题。@Maxwell Apple明确表示不要在文档中子类化
UIAlertView
UIAlertController
。看下面的答案。@stevekohls你是对的。我应该重写哪些类的方法?我尝试了显示UIAlertController的视图控制器,但崩溃仍然存在。我本以为我有此功能,但我意外地使用了UIDeviceOrientationGrait而不是UIInterfaceOrientationMaskPortrait。添加了上述方法,但我的应用程序仍然存在问题。这解决了我的问题。替换Alertview将需要大量的工作:)