Application tried to present <_SFAppPasswordSavingViewController> 崩溃治理

一. 背景

线上捕获到了关于_SFAppPasswordSavingViewController的相关崩溃。具体崩溃堆栈如下:

这个崩溃出现在钱包提现输入密码页面。

二. 原因分析

从崩溃原因分析:

vbnet 复制代码
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally a view controller <_SFAppPasswordSavingViewController: 0x120d60030> that is already being presented by <UIKeyboardHiddenViewController_Save: 0x123849e30>.
UserInfo:(null)'

是因为Application尝试去present存储密码_SFAppPasswordSavingViewController页面,但这个_SFAppPasswordSavingViewController已经present过,导致出现这个崩溃。而从产生该崩溃系统分析来看,这个崩溃基本发生在iOS16及相关系统,从目前来看应该是系统原因,主要出现键盘弹起自动密码填充界面。

我们从苹果论坛上面也能看到关于这个crash的相关反馈:

developer.apple.com/forums/thre...

里面有人提到针对这个崩溃的解决方法如下:

github.com/hackiftekha...

也就是hookUIViewControllerpresentViewController:animated:completion:方法,然后在hook方法里面添加判断当前的VCpresentedViewController是否有值,如果为nil,表示还没present过,直接调用``presentViewController:animated:completion:,如果有值,表示当前VC已经present过了,直接return`。

scss 复制代码
#import "UIViewController+PresentKBHook.h"

@implementation UIViewController (PresentKBHook)

+ (void)load {
    [UIViewController ff_swizzleInstanceMethodWithSrcClass:[UIViewController class] srcSel:@selector(presentViewController:animated:completion:) swizzledSel:@selector(cr_presentViewController:animated:completion:)];
}

- (void)cr_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
    if (self.presentedViewController) {
        NSLog(@"[present devil]self=%@,toPresent=%@",self.description, viewControllerToPresent.description);
    }else{
        [self cr_presentViewController:viewControllerToPresent animated:flag completion:completion];
    }
}

/**
 Implementation of exchanging two object methods
 */
+ (void)ff_swizzleInstanceMethodWithSrcClass:(Class)srcClass
                                      srcSel:(SEL)srcSel
                                 swizzledSel:(SEL)swizzledSel{
    
    Method srcMethod = class_getInstanceMethod(srcClass, srcSel);
    Method swizzledMethod = class_getInstanceMethod(srcClass, swizzledSel);
    if (!srcClass || !srcMethod || !swizzledMethod) return;
    
    //Add a layer of protection measures. If the method is added successfully, it means that the method does not exist in this class, but exists in the parent class, and the method of the parent class cannot be exchanged, otherwise the method will crash when the parent class object calls the method; Adding failure indicates that the method exists in this class
    BOOL addMethod = class_addMethod(srcClass, srcSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
    if (addMethod){
        //After the IMP is successfully implemented by adding methods, the original implementation will be replaced with the swizzledMethod method to achieve method exchange without affecting the implementation of the parent method
        class_replaceMethod(srcClass, swizzledSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod));
    }else{
        //Adding failed, calling the implementation of the two interactive methods
        method_exchangeImplementations(srcMethod, swizzledMethod);
    }
}

@end

三. 解决方案

  • 添加降级开关、添加系统版本判断、只在iOS 16相关系统启用该崩溃治理。
swift 复制代码
    /// 键盘崩溃修复策略
    public struct FJFPresentCrashFixPolicy: HandyJSON {
        /// presnet事件 崩溃修复
        public var viewControllerPresentCrashFixEnable: Bool = false
        /// 开始 修复 版本
        public var startFixVersion: String = "16.0"
        /// 结束 修复 版本
        public var endFixVersion: String = "17.0"
        
        public init() {}
    }
    
    /// 是否为需要修复的系统版本
     public static func isNeedToFixSystemVersionCrash(startVersion: String, endVersion: String) -> Bool {
        let curVersion = UIDevice.current.systemVersion
        if curVersion.compare(startVersion, options: .numeric) == .orderedDescending,
           curVersion.compare(endVersion, options: .numeric) == .orderedAscending {
            return true
        }
        return false
    }
}
相关推荐
wordbaby9 分钟前
🎯 satisfies 关键字详解(TypeScript)
前端·typescript
超级土豆粉19 分钟前
CSS 性能优化
前端·css·性能优化
Mintopia22 分钟前
光影魔术师的秘密:用 JavaScript 打造软阴影的奇幻世界
前端·javascript·计算机图形学
Mintopia34 分钟前
Three.js 粒子系统:让代码化身奇幻造梦师
前端·javascript·three.js
itwlz1 小时前
vite配置@别名,以及如何让IDE智能提示路经
开发语言·前端·javascript
lichenyang4531 小时前
添加按钮跳转页面并且根据网站的用户状态判断是否显示按钮
开发语言·前端·javascript
皮皮高1 小时前
itvbox绿豆影视tvbox手机版影视APP源码分享搭建教程
android·前端·后端·开源·tv
Hilaku1 小时前
JavaScript 里的 !0、!1 到底是啥?聊聊那些压缩器最爱的“极简写法”
前端·javascript
全栈陈序员1 小时前
前端文件下载常用方式详解
前端·javascript·chrome·ajax·css3·html5·safari
二十一_2 小时前
🤖✨ ChatGPT API深度体验:让AI看懂图片、听懂语音、调用你的代码
前端·chatgpt·openai