美文网首页
iOS崩溃错误分析记录

iOS崩溃错误分析记录

作者: GUIYIVIEW | 来源:发表于2022-02-11 16:30 被阅读0次

记录各种疑难杂症

1. Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES'

由于APP只支持竖屏,而在其中某个页面中单独设置支持横屏,在此横屏页面下,如果触发了某个业务弹出了UIAlertController,则会导致崩溃。网上有说写一个UIAlertController分类,在其中重写shouldAutorotate方法处理,然而写了之后并不会执行。
当然不仅仅是UIAlertController这一种情况,UIImagePickerViewController这种系统的东西都有可能触发。
解决方案:在AppDelegate中实现以下方法根据实际业务判断处理

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    UIViewController *rootVC = window.rootViewController;
    if (rootVC.presentedViewController) {
        UIViewController *theVC = rootVC.presentedViewController;
        while (theVC.presentedViewController) {
            theVC = theVC.presentedViewController;
        }
        if ([theVC shouldAutorotate]) {
            return UIInterfaceOrientationMaskAll;
        }
        return theVC.supportedInterfaceOrientations;
    }
    return rootVC.supportedInterfaceOrientations;
}

相关文章

网友评论

      本文标题:iOS崩溃错误分析记录

      本文链接:https://www.haomeiwen.com/subject/natzkrtx.html