zoukankan      html  css  js  c++  java
  • 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 .

    }

  • 相关阅读:
    第二次结对编程作业
    第5组 团队展示
    第一次结对编程作业
    BETA 版冲刺前准备(团队)
    项目测评(团队)
    1111111111
    Alpha 事后诸葛亮
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
  • 原文地址:https://www.cnblogs.com/linusflow/p/8688314.html
Copyright © 2011-2022 走看看