iphone - 从 UIWebView 中清除凭据

标签 iphone uiwebview nsurlconnection nsurlcredential

我在这里所做的是获取具有身份验证的 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/

相关文章:

iphone - UIButton - 我们应该释放还是不释放?

ios4 - 如何在 iphone 的 uiwebview 中更改电话号码的颜色

ios - 从 UIwebview 打开并安装 iOS 应用程序

iphone - iOS4 实现-[NSURLConnection sendAsynchronousRequest :queue:completionHandler:]?

ios - 有没有办法强制异步 NSURLConnection 在后台调用 connectionDidFinishLoading?

ios - 当应用程序处于后台时,苹果是否允许声音检测?

html - Iphone 7 Safari 文本跳转问题

iphone - 使用 MPMoviePlayerController 的连续背景音频?

ios - Cordova iOS ITMS-90809 : Deprecated API Usage - New apps that use UIWebView are no longer accepted

ios - 需要帮助从 iOS 设备上传多个大图像