What i am doing here is, fetching a URL which has authentication. Hence, i use the function
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
When it faces authentication, i present a UIAlertView to enter the username and password and if user has entered it correctly, this method is called.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
in this method, i make the login window disappear and bring in the detail view.
Problem arose, when i wanted a logout functionality. All i want is to remove the credentials entered by the user and fetch that URL again, for authentication= purpose. So, i call the didReceiveAuthenticationChallenge.
But what happens is it directly goes to the didReceiveResponse method without asking anything. The problem here is that i am not able to clear the credentials. Can you help me in doing this?
Thanks a lot in advance!
I know this is an old question, but I have the answer here:
It turns out that cookies aren't the only way that UIWebView stores data. There's also this persistent thing called NSURLCredentialStorage and the only way to clear it is thus:
You''ll find that the usernames show the first time, but don't show when checking the second time through the same loop. They've been deleted from the NSURLProtectionSpaces.
-Sean
Great question, and in my case I couldn't figure out why we couldn't log out of a web view.
I used some code from the first answer, but wanted to delete all the cookies in the whole thing rather than just ones associated with a certain string or URL. Here's what I did:
And this worked! Now when you logout it goes back to the original login screen every time.
Try Code for Clear cookie of Request