處理WKContentView的crash

liuhuila 7年前發布 | 16K 次閱讀 iOS開發 移動開發

解決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; }</code></pre>

 

來自:http://www.jianshu.com/p/7ef5814a871b

 

 本文由用戶 liuhuila 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!