解決WKContentView沒有isSecureTextEntry方法造成的crash
在程式啟動,或者webview開啟之前呼叫下以下方法
/**
處理WKContentView的crash
[WKContentView isSecureTextEntry]: unrecognized selector sent to instance 0x101bd5000
*/
+ (void)progressWKContentViewCrash {
//由於客戶端只支援8.0以上版本,所以不用判斷系統版本
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
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) {
LOGINFO(@"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;
}
複製程式碼
注:這裡也是在網上搜來的,這裡只作為自己積累所用