UIAlertView在iOS 8.3中崩溃
最近我开始只接收使用iOS 8.3的用户的UIAlertView的崩溃报告
Crashlytics报告:
致命exception:UIApplicationInvalidInterfaceOrientation支持的方向与应用程序没有共同的方向,[_UIAlertShimPresentingViewController shouldAutorotate]返回YES
发生崩溃的行是[alertView show]:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil]; [alertView show];
该代码在应用程序很长一段时间,现在开始崩溃。 有没有人遇到类似的行为,并解决了这个问题?
尝试通过实施这一点
- (BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
检查这也是: 在iPhone中的iOS 7中打开相机时在Lanscape模式中的方向问题
主要的是:
UIApplicationInvalidInterfaceOrientation支持的方向与应用程序没有共同的方向
这意味着你有一个地方实施
- (NSUInteger)supportedInterfaceOrientations { return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait }
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0
在这个函数中,必须返回Mask :
UIInterfaceOrientation Mask是1的肖像
比这更好,你应该开始使用UIAlertController
。 它有更好的function,也为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];
重要提示 : UIAlertView在iOS 8中已弃用。 (请注意, UIAlertViewDelegate也被弃用。)要在iOS 8及更高版本中创build和pipe理警报,请使用带有UIAlertControllerStyleAlert的preferredStyle的UIAlertController 。
在这里尝试解决scheme后,他们都没有为我工作。 我在一个应用程序中支持iOS 6-8,更重要的是,使用一些在内部使用UIAlertView的库,所以只要有条件地编译使用UIAlertController(当不可用时)。
我想出了一个解决scheme,为我解决了这个问题。 你的旅费可能会改变。 我将头文件包含在Header Prefix文件中,以确保它显示在UIAlertView的任何位置。
我在这里发布这个任何人谁绊倒这个问题,并find解决scheme的networking不起作用。 希望这是有帮助的。
我创build了一个助手,用于在iOS8之前显示UIAlertView,并在iOS8之后显示UIAlertController,这样可以解决旋转崩溃,并且在所有版本中都能很好地显示。