元元 2019-11-17
缺点
资源访问机制

// 网页开始加载的时候调用
- (void )webViewDidStartLoad:(UIWebView  *)webView{
}
// 网页加载完成的时候调用
- (void )webViewDidFinishLoad:(UIWebView  *)webView{
}
// 网页加载错误的时候调用
- (void)webView:(UIWebView *)webView  didFailLoadWithError:(NSError *)error{
}

在每个版本会提供一些API,前端会有一个对应的框架团队对其进行封装,释放业务接口
/**login*/
 CHRJSBridge.call("pagetansNative", {
 action: "pagetansNative", //type类型是跳转native的
 params: {
   controllername: "to_login" //跳转native的对应页
 },
 isbacktomain: 0, //跳转后是否关闭当前,默认false
 callbackFun:(params)=>{this.id=params.id}// 回调函数
 });handleConfirm(params) {
  let jsonStr = JSON.stringify(params);
  if (this.isIOS()) {
    window.webkit.messageHandlers.testMethod.postMessage(jsonStr)
  } else {
    javascript: chrclient.onJsActionRequest(jsonStr)
  }
}## native to js
window.nativeMethod = function(methodrParams) {
 console.log("nativeMethod");
 let actionName = JSON.parse(methodrParams).action;
 let actionParams = JSON.parse(methodrParams).params;
 //console.log("methodrParams=====", actionName, actionParams);
 window[actionName](actionParams);
}## 2. 封装的CHRJSBridge/JavaScriptCore
 主体内容:

## 3. 这样做有一个前提是,Native本身已经十分稳定了.测试包
- 1.设置里面清除缓存。 - 2.查看安装包版本信息 - 3..查看cookie信息 - 4.提供扫描二维码打开网页。供前期没有开通入口,FE自测
## 4. H5-native
url scheme Native能捕捉webview发出的一切请求
var messagingIframe = document.createElement('iframe');
messagingIframe.style.display = 'none'
document.documentElement.appendChild(messagingIframe);
messagingIframe.src = url注意,正常来说是可以通过window.location.href达到发起网络请求的效果的,但是有一个很严重的问题,就是如果我们连续多次修改window.location.href的值,在Native层只能接收到最后一次请求,前面的请求都会被忽略掉。所以JS端发起网络请求的时候,需要使用iframe,这样就可以避免这个问题

5.参考资料