处理WKContentView的crash

liuhuila 7年前
   <h3>解决WKContentView没有isSecureTextEntry方法造成的crash</h3>    <p>程序中有web页面,使用WKWebView,但是有个crash一直存在:</p>    <p>[WKContentView isSecureTextEntry]: unrecognized selector sent to instance 0x101bd5000</p>    <p>网上搜索,并没有结果,是太简单了吗?不清楚,准备使用runtime给WKContentView添加一个方法,观察下</p>    <p>在程序启动的时候调用一下progressWKContentViewCrash方法就可以</p>    <pre>  <code class="language-objectivec">/**   处理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;  }</code></pre>    <p> </p>    <p>来自:http://www.jianshu.com/p/7ef5814a871b</p>    <p> </p>