缺點javascript
資源訪問機制html
// 網頁開始加載的時候調用 - (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 jsjava
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
主體內容:web
## 3. 這樣作有一個前提是,Native自己已經十分穩定了.測試包json
- 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,這樣就能夠避免這個問題cookie
5.參考資料網絡