webview重新加载(reload)或者发起 redirect request导致js和objc代码之间的bridge失联解决方案(亲测有效)...
生活随笔
收集整理的這篇文章主要介紹了
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 .
//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 .
}
轉載于:https://www.cnblogs.com/linusflow/p/8688314.html
總結
以上是生活随笔為你收集整理的webview重新加载(reload)或者发起 redirect request导致js和objc代码之间的bridge失联解决方案(亲测有效)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【算法总结】二分搜索
- 下一篇: 打造万能的Python开发环境