How did (NSURLCredential *) suggest Credential in iOS work?

Morning

I was working on creating an iOS application that uses stored credentials in NSURLCredentialStorage for a specific security space. Now I realized that I am using proposedCredential to retrieve the stored credentials.

My problem is that it returns null , and I can not find any good explanation of what the proposedCredential actually does and why it does not return what I think it should.

This is what I do:

First, I define NSURLProtectionSpace , give the credentials, and save them to NSURLCredentialStorage . I have already verified that this is done before I refer to the proposedCredential and that the credentials that I pass are correct.

 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]; } 

Can someone tell me what the proposedCredential actually does, what it compares together to find out if there are credentials that it needs to pass, and what is it that I may be missing in the code?

For reference, I read an Apple document, specifically this , this and this

All help would be appreciated.

+6
source share

Source: https://habr.com/ru/post/920960/


All Articles