NSURLCredential是永久性的吗?

时间:2011-06-03 11:18:59

标签: ios objective-c nsurlconnection nsurlcredential

我们的iPhone模拟器出现问题,原因是使用此行:

    Foo = [NSURLCredential CredentialWithUser:foo 
    password:bar persistance:NSURLCredentialPersistencePermanent];

问题是在

处为挑战提供凭据时创建的
        -(NSURLConnection *)connection
        didReceiveAuthenticationChallenge(NSURLAuthenticationChallenge *)challenge
    {

        [[challenge sender]useCredential:Foo forAuthenticationChallenge:challenge]      
    }

所以现在当我们运行应用程序时,我们再也不会遇到身份验证挑战,这很奇怪,即使我们将凭据更改为

    Foo = [NSURLCredential CredentialWithUser:foo 
    password:bar persistance:NSURLCredentialPersistenceForSession];

or even

    Foo = [NSURLCredential CredentialWithUser:foo
    password:bar persistance:NSURLCredentialPersistenceNone];

总结:

通过使用credentialpersistencepermanent,凭证以某种方式保存在某处并自动使用以访问我们需要自我验证的任何地方。

因此,出于测试目的,我们非常希望删除此持久性...凭据。

任何想法? :)

2 个答案:

答案 0 :(得分:4)

您是否尝试过重置模拟器?它在模拟器菜单中。

答案 1 :(得分:2)

它保存在钥匙串中。要从NSURLCredentialPersistencePermanent转到较不常见的状态NSURLCredentialPersistenceForSession,您必须将其删除并重新创建。

请注意,在某些版本的工具中,重置模拟器不会清除钥匙串。