I've seen many questions that ask (and answer) how to supply credentials when you know beforehand that the request requires them.
When I load a site that requests an authentication challenge, (responds with HTTP 401), my UIWebViewDelegate
only receives the following callbacks: webView:shouldStartLoadWithRequest:navigationType:
and sometimes webViewDidStartLoad:
(webViewDidStartLoad:
seems to be called if I navigate directly to the site, and it seems not to be called if I'm redirected there).
By overriding -[NSObject respondsToSelector:]
, the UIWebViewDelegate
receives some calls to uiWebView:resource:canAuthenticateAgainstProtectionSpace:forDataSource:
and uiWebView:resource:didReceiveAuthenticationChallenge:fromDataSource:
, which could be useful, but of course those are private API and will probably get my app rejected.
I've tested a few different mainstream apps with embedded UIWebView
s. So far, only Chrome handles these authentication challenges properly. I've even set up my own server and validated that Chrome only POST
s once. Twitter and Tweetbot fail just show the loading screen forever, just like mine.
Is there another (probably very hacky) way to detect these authentication challenges other than using a second speculative NSURLConnection
? If I make a POST
request, that will double-POST
everything, which is bad.
I've added a radar to request an enhancement to UIWebView for this. Please duplicate it.