UIAlertView在iOS 8.3中崩溃

时间:2015-04-09 09:00:26

标签: ios objective-c uialertview

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

Crashlytics报道:

  

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

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

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

该代码在应用程序中存在了很长时间,现在它开始崩溃。有没有人遇到类似的行为并解决了这个问题?

6 个答案:

答案 0 :(得分:10)

主要是:

  

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

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

- (NSUInteger)supportedInterfaceOrientations {

    return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0

在该功能中必须返回面具,如:

UIInterfaceOrientation 面具 1

的肖像

答案 1 :(得分:9)

尝试实施此

- (BOOL)shouldAutorotate {
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

另请检查:Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone

答案 2 :(得分:1)

比这更好,你应该开始使用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];

答案 3 :(得分:0)

重要 :iOS 8中不推荐使用 UIAlertView (请注意, UIAlertViewDelegate 也已弃用。)要在iOS 8及更高版本中创建和管理警报,请改为使用 UIAlertController ,并使用 UIAlertControllerStyleAlert 的preferredStyle。

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

答案 4 :(得分:0)

在这里尝试解决方案之后,它们都没有为我工作。我在一个应用程序中支持iOS 6-8,而且,更重要的是,使用一些内部使用UIAlertView的库,因此只有有条件地编译才能在可用时使用UIAlertController。

我提出了一个解决问题的解决方案。你的旅费可能会改变。我将头文件包含在Header Prefix文件中,以便它确保包含在显示UIAlertView的任何位置。

我在这里发布这个帖子给那些在这个问题上磕磕绊绊的人以及在网络上发现的解决方案。希望它有所帮助。

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

答案 5 :(得分:0)

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

https://github.com/dannyshmueli/DSAlertDisplayer

相关问题