我在这里所做的是获取具有身份验证的 URL。因此,我使用该功能
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
当它面临身份验证时,我呈现一个 UIAlertView 来输入用户名和密码,如果用户输入正确,则调用此方法。
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
在此方法中,我使登录窗口消失并引入详细 View 。
问题出现了,当我想要注销功能时。我想要的只是删除用户输入的凭据并再次获取该 URL,以进行身份验证= 目的。因此,我调用 didReceiveAuthenticationChallenge。
但是发生的情况是它直接转到 didReceiveResponse 方法,而不询问任何内容。这里的问题是我无法清除凭据。你能帮我做这件事吗?
提前非常感谢!
最佳答案
尝试清除请求的 cookie 代码
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];
}
}
关于iphone - 从 UIWebView 中清除凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7256808/