Hra*_*afn 6 https objective-c nsurlconnection nsurlcredential ios
早上
我一直致力于创建一个iOS应用程序,该应用程序使用存储的凭据NSURLCredentialStorage进行特定的保护空间.我现在已经到了proposedCredential用于获取存储凭据的地步.
我的问题是它正在回归null,而我似乎无法找到任何关于proposedCredential实际做什么以及为什么它没有返回我认为它应该返回的任何好的解释.
这就是我正在做的事情:
首先,我定义一个NSURLProtectionSpace,给出凭据并将它们存储在NSURLCredentialStorage.我已经检查过这是在我引用之前完成的,proposedCredential并且我传递的凭据是正确的.
NSURLProtectionSpace *protectionSpaceOne = [[NSURLProtectionSpace alloc]
initWithHost:xyz
port: 80
protocol:NSURLProtectionSpaceHTTP
realm:nil
authenticationMethod:NSURLAuthenticationMethodDefault];
//credential is initiated elsewhere.
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpaceOne];
-(void)connection:(NSURLConnection *)connection didRecieveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
//Has the authentication failed before?
if([challenge previousFailureCount]>0){
//Why?
NSError *error = [challenge error];
//Here I respond to the failure count
[[challenge sender]cancelAuthenticationCallenge:challenge];
}
NSURLCredential *proposedCredential = [challenge proposedCredential];
}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我proposedCredential实际做了什么,它是什么比较在一起来弄清楚它是否应该传递一个凭证,以及我可能从代码中遗漏了什么?
作为参考,我一直在阅读Apple文档,特别是这个,这个,以及这个
所有帮助将不胜感激.
| 归档时间: |
|
| 查看次数: |
930 次 |
| 最近记录: |