may*_*uur 5 iphone uiwebview nsurlconnection nsurlcredential
我在这里做的是,获取一个具有身份验证的URL.因此,我使用该功能
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
Run Code Online (Sandbox Code Playgroud)
当它面向身份验证时,我提供UIAlertView输入用户名和密码,如果用户输入正确,则调用此方法.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
Run Code Online (Sandbox Code Playgroud)
在这个方法中,我使登录窗口消失并引入详细视图.
当我想要注销功能时出现问题.我想要的是删除用户输入的凭据并再次获取该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];
}
}
Run Code Online (Sandbox Code Playgroud)