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