Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear the credentials from UIWebView

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!

like image 380
mayuur Avatar asked Aug 31 '11 12:08

mayuur


People also ask

How can I clear the contents of a UIWebView Wkwebview?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .


1 Answers

Try Code for Clear cookie of Request

NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
    NSString* domainName = [cookie domain];
    NSRange domainRange = [domainName rangeOfString:@"twitter"];
    if(domainRange.length > 0)
    {
        [storage deleteCookie:cookie];
    }
}
like image 156
Sujal Avatar answered Oct 08 '22 12:10

Sujal