UIWebView does not initially load certain URLs

2019-07-05 14:53发布

Having such a bizarre issue with the UIWebView and I haven't been able to find a solution online. I have an iPad app that has a web view in it. Upon first install and run of the app, I try to load an education website. The web view just hangs and times out. I kill the app, I run it again, and it loads just fine. This one works fine which is also part of the education website. I'm pulling my hair out!

Some code:

-(void)viewDidAppear:(BOOL)animated
{
   NSURL *websiteUrl = [NSURL URLWithString:@"http://my.tac.edu.au"];
   NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
   [self.webView loadRequest:urlRequest];
}

Works fine with www.tac.edu.au. I don't know what it is about that URL that makes it hang only when the app is first installed. You stop it, run it again (without uninstalling) and it comes up just fine. Any help would be appreciated.

标签: ios uiwebview
1条回答
仙女界的扛把子
2楼-- · 2019-07-05 15:21

:)

instead of view did appear , write the code in view will appear

-(void)viewWillAppear:(BOOL)animated
{
   NSURL *websiteUrl = [NSURL URLWithString:@"http://my.tac.edu.au"];
   NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL: websiteUrl];
   [self.webView loadRequest:urlRequest];
   self.webview.delegate = self;
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
  //Start Activity Indicator
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{

   //End activity indicator
}
查看更多
登录 后发表回答