从UIWebView清除凭据 [英] Clear the credentials from UIWebView

查看:117
本文介绍了从UIWebView清除凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里做的是,获取具有身份验证的URL。因此,我使用函数

What i am doing here is, fetching a URL which has authentication. Hence, i use the function

  - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

当面对身份验证时,我会提供一个UIAlertView来输入用户名和密码,如果用户输入了正确地说,这个方法被调用。

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.

问题出现,当我想要退出功能时。我想要的是删除用户输入的凭据并再次获取该URL,以进行身份​​验证=目的。所以,我称之为 didReceiveAuthenticationChallenge

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.

但是,它会直接转到 didReceiveResponse 方法,而不会询问任何内容。这里的问题是我无法清除凭据。你可以帮我这么做吗?

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?

提前多多谢谢!

推荐答案

尝试使用代码清除Cookie请求

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];
    }
}

这篇关于从UIWebView清除凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆