如何在iOS中删除用于https身份验证的NSURLCredential存储

时间:2014-06-02 12:45:16

标签: ios nsurlconnection nsurlcredential nsurlcredentialstorage

我需要在收到每个https请求的响应后每次都删除NSURLCredential存储。在我的情况下,情况并非如此。以下方法仅针对第一次请求执行,对于未调用的下一个请求。当我重新启动应用程序时,它会被调用。我在SO中尝试了很多建议,但没有帮助。我该如何解决这个问题?

    - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    SecTrustRef trust = challenge.protectionSpace.serverTrust;
    NSURLCredential *cred;
    cred = [NSURLCredential credentialForTrust:trust];
    [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
}

1 个答案:

答案 0 :(得分:0)

将凭据的persistence属性设置为NSURLCredentialPersistenceNone。这应该确保永远不会存储凭证以供将来使用(假设您还没有为iOS 2构建)。

相关问题