最近开发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
网友评论