Background Loading a url in a uiwebview

假如想象 提交于 2020-01-04 03:18:16

问题


Hi I'm a have an app in which i load webpage in a uiwebview .So each time it takes too much time for loading . So i need to load the webpage in a background mode. Any one know how to done this.

Any help would be appreciable.


回答1:


- (void) start_Web_View {
     UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
     wv.delegate = self;
     [wv loadRequest:
          [NSURLRequest requestWithURL:
                    @"http://long_loading_web_site"]];
      // go do something else to amuse the user while the web site loads...
  }


 #pragma mark webview delegate
 - (void) webViewDidFinishLoad:(UIWebView *)webView {
     [self.view addSubview: webView];  // load is done, so add the webview to self.view so it's visible.
 }



回答2:


Do you want to pre-load that other URL, so when it loads in the main webView it loads faster (or it's already loaded)?

You could create another UIWebView and don't show it at all, and make it load the other URL (you can set the frame of it outside the screen bounds).

Example:

UIWebView *dummyWebView = [[UIWebView alloc] init];
dummyWebView.frame = CGRectMake(-1, -1, 1, 1);


来源:https://stackoverflow.com/questions/7418815/background-loading-a-url-in-a-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!