iOS打包审核webview

[WebActionDisablingCALayerDelega

2018-09-06  本文已影响115人  FuWees

ios的webview在xcode全局断点打开时,某些webview页面会抓到如下异常:“[WebActionDisablingCALayerDelegate willBeRemoved]: unrecognized selector sent to instance 0x604000204ff0”,不一定会crash,但出于强迫症还是fix一下这个问题。
错误原因:H5的页面中touch事件和鼠标事件冲突导致的。
解决方法:1.让H5的开发同事找出问题改之。
2.我们原生端通过runtime给webview写一个空方法,防止crash或者异常。
3.webvie换成wkwebview加载url

下面针对法2,给出代码:

@interface H5ViewController ()<UIWebViewDelegate>

id setBeingRemoved(id self, SEL selector, ...);
id willBeRemoved(id self, SEL selector, ...);

@end

@implementation H5ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  /** 此处初始化webview,具体代码省略 **/

  //此处给webview增加容错方法
  [self webViewAddMethods];
  
}

- (void)webViewAddMethods{
  
  //预防报错:WebActionDisablingCALayerDelegate    willBeRemoved
  Class class = NSClassFromString(@"WebActionDisablingCALayerDelegate");
  class_addMethod(class, NSSelectorFromString(@"setBeingRemoved"), setBeingRemoved, "v@:");
  class_addMethod(class, NSSelectorFromString(@"willBeRemoved"), willBeRemoved, "v@:");
  
  class_addMethod(class, NSSelectorFromString(@"removeFromSuperview"), willBeRemoved, "v@:");
}

id setBeingRemoved(id self, SEL selector, ...)
{
  return nil;
}

id willBeRemoved(id self, SEL selector, ...)
{
  return nil;
}

#pragma mark - UIWebViewDelegate
/** 此处写webview代理方法,具体代码省略*/


@end
上一篇下一篇

猜你喜欢

热点阅读