• ios 处理WKContentView的crash


     
     

    解决WKContentView没有isSecureTextEntry方法造成的crash

    程序中有web页面,使用WKWebView,但是有个crash一直存在:
    [WKContentView isSecureTextEntry]: unrecognized selector sent to instance 0x101bd5000
    网上搜索,并没有结果,是太简单了吗?不清楚,准备使用runtime给WKContentView添加一个方法,观察下


    在程序启动的时候调用一下progressWKContentViewCrash方法就可以

    /**
     处理WKContentView的crash
     [WKContentView isSecureTextEntry]: unrecognized selector sent to instance 0x101bd5000
     */
    + (void)progressWKContentViewCrash {
        if (([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)) {
            const char *className = @"WKContentView".UTF8String;
            Class WKContentViewClass = objc_getClass(className);
            SEL isSecureTextEntry = NSSelectorFromString(@"isSecureTextEntry");
            SEL secureTextEntry = NSSelectorFromString(@"secureTextEntry");
            BOOL addIsSecureTextEntry = class_addMethod(WKContentViewClass, isSecureTextEntry, (IMP)isSecureTextEntryIMP, "B@:");
            BOOL addSecureTextEntry = class_addMethod(WKContentViewClass, secureTextEntry, (IMP)secureTextEntryIMP, "B@:");
            if (!addIsSecureTextEntry || !addSecureTextEntry) {
                NSLog(@"WKContentView-Crash->修复失败");
            }
        }
    }

    /**
     实现WKContentView对象isSecureTextEntry方法
     @return NO
     */
    BOOL isSecureTextEntryIMP(id sender, SEL cmd) {
        return NO;
    }

    /**
     实现WKContentView对象secureTextEntry方法
     @return NO
     */
    BOOL secureTextEntryIMP(id sender, SEL cmd) {
        return NO;
    }
     
    app delegate:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     
     //处理crash
        [AppCrashProcessManager progressCrash];
    }
  • 相关阅读:
    OMFCL 使用
    客户化 Summary 页的 Properties
    瑞星升级包下载
    观察者模式Observer
    单例模式Singleton
    java中8大排序
    向上转型和向下转型
    瀑布流的实现
    [转]降级论
    Grid的使用
  • 原文地址:https://www.cnblogs.com/xsyl/p/6419509.html
Copyright © 2020-2023  润新知