UIWebView does not persist authentication on iOS3.2/iOS4

夙愿已清 提交于 2020-01-05 04:57:13

问题


I made an application that uses UIWebView to display a site that uses basic authentication. It stopped displaying the content since iOS3.2 (on both iPhone and iPad).

My approach for authenticating users are:

  1. create a NSURLConnection
  2. implement didReceiveAuthenticationChallenge to provide the credential
  3. implement didReceiveResponse to receive the response and load the request in a UIWebView, i.e. [webView loadRequest:]

Ever since iOS3.2, the authentication was broken; UIWebView doesn't seem to check against the shared credential storage any more.

For iOS4 on iPhone, I managed to work around this issue by, stupidly, including the login informatino in the URL (i.e. https://username:password@www.somesite.com) to the initial load request passed to the webView.

For iOS3.2 on iPad, that isn't enough. The initial request is authenticated all right, but the subsequent calls still aren't authenticated.

Any suggestions?


回答1:


Use setDefaultCredential:forProtectionSpace: on the shared NSURLCredentialStorage the Webview still uses the default credential, it does not work when you use setCredential:forProtectionSpace.



来源:https://stackoverflow.com/questions/3349240/uiwebview-does-not-persist-authentication-on-ios3-2-ios4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!