iOS App - Set Timeout for UIWebView loading

后端 未结 4 1392
小蘑菇
小蘑菇 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:23

    Swift coders can do it as follow:

    var timeOut: NSTimer!
    
       func webViewDidStartLoad(webView: UIWebView) {
        self.timeOut = Timer.scheduledTimer(timeInterval: 7.0, target: self, selector: Selector(("cancelWeb")), userInfo: nil, repeats: false)
    }
    
    func webViewDidFinishLoad(webView: UIWebView) {
        self.timeOut.invalidate()
    }
    
    func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
        self.timeOut.invalidate()
    }
    
    func cancelWeb() {
        print("cancelWeb")
    }
    

提交回复
热议问题