iOS崩溃错误分析记录

记录各种疑难杂症

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

2. iOS 16实时活动API,在iPhone上没问题,在M1上打开闪退。

闪退堆栈

* thread #26, queue = 'com.apple.root.user-initiated-qos.cooperative', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001a37e442c libswiftCore.dylib`swift::ResolveAsSymbolicReference::operator()(swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*) + 176
    frame #1: 0x00000001a380ee3c libswiftCore.dylib`swift::Demangle::__runtime::Demangler::demangleSymbolicReference(unsigned char) + 228
    frame #2: 0x00000001a380b1cc libswiftCore.dylib`swift::Demangle::__runtime::Demangler::demangleType(__swift::__runtime::llvm::StringRef, std::__1::function) + 264
    frame #3: 0x00000001a37ec3e4 libswiftCore.dylib`swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function const* (unsigned int, unsigned int)>, std::__1::function const* (swift::TargetMetadata const*, unsigned int)>) + 504
    frame #4: 0x00000001a37e7a3c libswiftCore.dylib`swift_getTypeByMangledName + 832
    frame #5: 0x00000001a37e7d4c libswiftCore.dylib`swift_getTypeByMangledNameInContext + 164
    frame #6: 0x0000000103d2b1c4 XXXX`__swift_instantiateConcreteTypeFromMangledName at :0
    frame #7: 0x0000000103d2b408 XXXX`partial apply for closure #1 in static Bridge.stop(_:) at :0
    frame #8: 0x0000000103d2b784 XXXX`thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) at :0
    frame #9: 0x0000000103d2c1ac XXXX`partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) at :0

定位代码

Activity.activities

只要写了这个API,即便是不做其他事情,也会闪退,最终只能判断在iPad上不调用。
一开始无法定位,bugly上只有__swift_instantiateConcreteTypeFromMangledName,通过这个搜索到的都是说OC与Swift类型转换的问题,完全误导了排查方向。

你可能感兴趣的:(iOS崩溃错误分析记录)