前言:

每当到 618、双 11 这样大促的时候,搜索作为整个 App 的核心功能,不仅担当着流量入口,还承载着用户感知到这个产品在导购场景中的服务与体验,所以保障搜索以便更好的助力 618 大卖。

现象:

搜狗输入框双击调起键盘 crash

监控平台:

监控平台检测到大量的 crash,现象都为在极短的时间间隔内键盘响应问题

心路历程:

App 是否崩溃 频率
京东
京东万商
七鲜
淘宝
支付宝
百度
百度地图
美团
盒马
1688
哔哩哔哩
抖音

源码调试:

解决方案:

static BOOL (*originalImpl)(id, SEL, UIResponder*, UIResponder*, UIEvent* ) = nil;


- (BOOL)_wantsForwardingFromResponder:(UIResponder *)arg1 toNextResponder:(UIResponder *)arg2 withEvent:(UIEvent *)arg3 {
    NSString* responderClassName = NSStringFromClass([arg2 class]);
    if ([responderClassName isEqualToString:@"_UIRemoteInputViewController"]) {
        bool isDeallocating = false;
        // isDeallocating = _objc_rootIsDeallocating(arg2);

        // Use 'performSelector' when u are develop a App-Store App.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        SEL sel = NSSelectorFromString(@"_isDeallocating");
        isDeallocating = [arg2 respondsToSelector:sel] && [arg2 performSelector:sel];
#pragma clang diagnostic pop

        if (isDeallocating) {
            NSLog(@"BingGo a deallocating object ...");
            return true;
        }
    }

    BOOL retVal = FALSE;
    if (originalImpl == nil) {
        IMP impl = [ObjcSeeker seekInstanceNextOirignalImpl:self selector:_cmd];
        originalImpl = (BOOL (*)(id, SEL, UIResponder*, UIResponder*, UIEvent* ))impl;
    }

    if (originalImpl != nil) {
        retVal = originalImpl(self, _cmd, arg1, arg2, arg3);
    }
    return retVal;
}




参考链接:

https://github.com/SnowGirls/Objc-Deallocating

作者:京东零售 涂世展

来源:京东云开发者社区


↙↙↙阅读原文可查看相关链接,并与作者交流