3

我遇到了无法从中检索凭据的问题NSURLCredentialStorage,即使我在保存后立即尝试此操作。

凭证格式正确并被服务器接受,它被设置为永久的。我有调试代码来打印并确认凭证具有身份和证书。但是,当我尝试从凭证存储中检索它时,调试会将所有值打印为 Null,而凭证本身不为 null。

如何从 NSURLCredentialStorage 正确检索凭据?

-(void)saveCredential:(NSURLCredential*)credential forProtectionSpace:(NSURLProtectionSpace*)protectionSpace
{

    CLog(@"ATTEMPTING SAVE:");
    [self debugCredential:credential]; //credential is properly formatted

    [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential
                                          forProtectionSpace:protectionSpace];


    NSURLCredential* retrievedTest = [[NSURLCredentialStorage sharedCredentialStorage]defaultCredentialForProtectionSpace:protectionSpace];

    CLog(@"ATTEMPTING RETRIEVAL:");
    [self debugCredential:retrievedTest]; //all values are null, credential is not null

}

-(void)debugCredential:(NSURLCredential*) credential
{

    CLog(@"DEBUG Credential: [%@]",credential);
    CLog(@"credential identity: %@", credential.identity);
    CLog(@"credential cert: %@", credential.certificates);
    CLog(@"credential persistence: %lu", (unsigned long)credential.persistence);
}

这是保存前后的日志

//before save
2016-02-17 16:24:19.669 GWNMobile[2925:716139] DEBUG Credential: [<NSURLCredential: 0x16ff6c00>: (null)]
2016-02-17 16:24:19.670 GWNMobile[2925:716139] credential identity: <SecIdentityRef: 0x16e24890>
2016-02-17 16:24:19.670 GWNMobile[2925:716139] credential cert: (
    "<cert(0x16f9c750) s: [Name] i: [Issuer]>"
)
2016-02-17 16:24:19.670 GWNMobile[2925:716139] credential persistence: 2

//after retrieval:
2016-02-17 16:24:19.670 GWNMobile[2925:716139] ==========================
2016-02-17 16:24:19.691 GWNMobile[2925:716139] ATTEMPTING RETRIEVAL:
2016-02-17 16:24:19.691 GWNMobile[2925:716139] DEBUG Credential: [(null)]
2016-02-17 16:24:19.691 GWNMobile[2925:716139] credential identity: (null)
2016-02-17 16:24:19.691 GWNMobile[2925:716139] credential cert: (null)
2016-02-17 16:24:19.691 GWNMobile[2925:716139] credential persistence: 0
4

0 回答 0