iOS App - Set Timeout for UIWebView loading

后端 未结 4 1393
小蘑菇
小蘑菇 2021-01-30 14:52

I have a simple iOS native app that loads a single UIWebView. I would like the webView to show an error message if the app doesn\'t COMPLETELY finish loading the initial page in

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 15:19

    The timeoutInterval is for connection. Once webview connected to the URL, you'll need to start NSTimer and do your own timeout handling. Something like:

    // define NSTimer *timer; somewhere in your class
    
    - (void)cancelWeb
    {
        NSLog(@"didn't finish loading within 20 sec");
        // do anything error
    }
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        [timer invalidate];
    }
    
    - (void)webViewDidStartLoad:(UIWebView *)webView
    {
        // webView connected
        timer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(cancelWeb) userInfo:nil repeats:NO];
    }
    

提交回复
热议问题