Archive

Posts Tagged ‘nsurlconnection’

How to Detect and Handle HTTP Status Codes in UIWebViews

August 18th, 2011 Ahmet Ardal 8 comments

Imagine you have the following problem: You want to load a url in a UIWebView. But the resource at that url requires authentication, and if the user is not authenticated the web page responds with a “403 Not Authenticated” without showing any other instructions on how to login or where to go next etc. Ideally you’d want to redirect the user to a page where she can log in and continue to browse the url. The problem is UIWebView does not provide any properties or methods for inspecting HTTP status codes. One workaround is to intercept the UIWebView request loading process and check whether the user is authenticated or not by loading the same url using an NSURLConnection and inspecting the response, then you can behave accordingly.
Read more…