UIAlertView 在 iOS 8.3 中崩溃
UIAlertView crashs in iOS 8.3
最近我开始收到只有使用 iOS 8.3
的用户的 UIAlertView 崩溃报告
Crashlytics 报告:
Fatal Exception: UIApplicationInvalidInterfaceOrientation
Supported orientations has no common orientation with the application, and [_UIAlertShimPresentingViewController shouldAutorotate] is returning 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 及更高版本中创建和管理警报,请改用 UIAlertController preferredStyle 为 UIAlertControllerStyleAlert.
比这更好的是,您应该开始使用 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;
}
也检查这个:Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone
主要是:
UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application
这意味着你已经在某个地方实现了
- (NSUInteger)supportedInterfaceOrientations {
return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0
在该函数中必须返回 Mask,例如:
UIInterfaceOrientationMaskPortrait 即 1
在尝试了此处的解决方案后,none 对我有用。我在一个应用程序中支持 iOS 6-8,除此之外,我还使用了一些在内部使用 UIAlertView 的库,所以简单地有条件地编译以在可用时使用 UIAlertController 不是一个选项。
我想出了一个解决方案,为我解决了这个问题。你的旅费可能会改变。我将头文件包含在 Header Prefix 文件中,以便确保它包含在显示 UIAlertView 的任何位置。
我将此张贴在此处,供遇到此问题且在网上找到的解决方案不起作用的任何人使用。希望对您有所帮助。
我创建了一个帮助程序,用于在 iOS8 之前显示 UIAlertView,在 iOS8 之后创建 UIAlertController,这解决了旋转崩溃问题,并且在所有版本中都显示得很好。
最近我开始收到只有使用 iOS 8.3
的用户的 UIAlertView 崩溃报告Crashlytics 报告:
Fatal Exception: UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application, and [_UIAlertShimPresentingViewController shouldAutorotate] is returning 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 及更高版本中创建和管理警报,请改用 UIAlertController preferredStyle 为 UIAlertControllerStyleAlert.
比这更好的是,您应该开始使用 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;
}
也检查这个:Orientation issue in Lanscape mode while opening camera in iOS 7 in iPhone
主要是:
UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application
这意味着你已经在某个地方实现了
- (NSUInteger)supportedInterfaceOrientations {
return UIDeviceOrientationPortrait; // or UIInterfaceOrientationPortrait
}
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait = 0
在该函数中必须返回 Mask,例如:
UIInterfaceOrientationMaskPortrait 即 1
在尝试了此处的解决方案后,none 对我有用。我在一个应用程序中支持 iOS 6-8,除此之外,我还使用了一些在内部使用 UIAlertView 的库,所以简单地有条件地编译以在可用时使用 UIAlertController 不是一个选项。
我想出了一个解决方案,为我解决了这个问题。你的旅费可能会改变。我将头文件包含在 Header Prefix 文件中,以便确保它包含在显示 UIAlertView 的任何位置。
我将此张贴在此处,供遇到此问题且在网上找到的解决方案不起作用的任何人使用。希望对您有所帮助。
我创建了一个帮助程序,用于在 iOS8 之前显示 UIAlertView,在 iOS8 之后创建 UIAlertController,这解决了旋转崩溃问题,并且在所有版本中都显示得很好。