How do I get the last HTTP Status Code from a UIWebView?

后端 未结 9 2172
栀梦
栀梦 2020-12-08 16:43

I would like to detect when a page load request give to a UIWebView has returned a status code in the 5xx or 4xx range.

I\'ve setup the delegate for the web view a

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 17:29

    As I just posted on another thread, it is also possible to intercept any NSURLRequest at the level of the NSURLProtocol and create your NSURLResponse there, instead of in your UIWebView delegate/controller. The reason why this is preferable in my opinion is that it maintains the back/forward navigation stack of the UIWebView. The outline of the approach can be found in this excellent blog post by Rob Napier:

    http://robnapier.net/blog/offline-uiwebview-nsurlprotocol-588

    and there's code on GitHub:

    https://github.com/rnapier/RNCachingURLProtocol

提交回复
热议问题