webview重新加載(reload)或者發起 redirect request導致js和objc代碼之間的bridge失聯解決方案(親測有效)


 
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { //isNotFirstLoad' marks if it is the fisrt load.

//isNotFirstLoad是代表當前這個webview是不是已經加載了一次request if (isNotFirstLoad) { //如果不加上這個判斷,后面出現的loadRequest函數的調用就會導致出現死循環 //create an new webview CGRect frame = _myWebView.frame; [_myWebView removeFromSuperview]; _myWebView = [[EasyJSWebView alloc] initWithFrame:frame]; [self.view addSubview:_myWebView]; //init the new webview _webView.delegate = self; javaScriptInterface* interface = [javaScriptInterface new]; [self.webView addJavascriptInterfaces:interface WithName:@"interface"]; [_myWebView loadRequest:request]; //reset the firstload flag to load the new request isNotFirstLoad = NO; //返回No,則不加載本方法傳入的的request return NO; } isNotFirstLoad = YES; return YES; //YES if the web view should begin loading content; otherwise, NO .

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM