处理解决-[WKContentView isSecureTextEntry]: unrecognized selector sent to instance 异常

最近开发iOS H5项目,发现点击H5页面,有极小概率触发-[WKContentView isSecureTextEntry]: unrecognized selector sent to instance 异常,查阅相关资料,也没有说明,没办法,那就给这个类加上这个方法吧。下面直接贴出解决方案。

#import <Foundation/Foundation.h>
#import <objc/runtime.h>

@interface  yourClass : NSObject

@end

@implementation  yourClass

#pragma mark - 处理解决-[WKContentView isSecureTextEntry]: unrecognized selector sent to instance 异常

+ (void)load {

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        if ([[UIDevice currentDevice].systemVersion floatValue]< 8.0) {

            return;

        }



        Class WKContentViewCls = objc_getClass("WKContentView");

        if (!WKContentViewCls) { return;}



        SEL isSecureTextEntrySel = @selector(isSecureTextEntry);

        if (![WKContentViewCls instancesRespondToSelector:isSecureTextEntrySel]) {

            BOOL isSecureTextEntryAdded = class_addMethod(WKContentViewCls, isSecureTextEntrySel, class_getMethodImplementation(self, isSecureTextEntrySel), "B@:");

            if (!isSecureTextEntryAdded) {

                NSLog(@"isSecureTextEntry 添加失败");

            }

        }

        SEL secureTextEntrySel = @selector(secureTextEntry);

        if (![WKContentViewCls instancesRespondToSelector:secureTextEntrySel]) {

            BOOL secureTextEntryAdded = class_addMethod(WKContentViewCls, secureTextEntrySel, class_getMethodImplementation(self, secureTextEntrySel), "B@:");

            if (!secureTextEntryAdded) {

                NSLog(@"isSecureTextEntry 添加失败");

            }

        }

    });

}

- (BOOL)isSecureTextEntry {

    return NO;

}

- (BOOL)secureTextEntry  {

    return NO;

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。