How does (NSURLCredential *) proposedCredential in iOS work?
Asked Answered
F

0

6

Morning

I've been working on creating a iOS application that uses stored credentials in NSURLCredentialStorage for a specific protectionspace. I've now gotten to the point where I'm using proposedCredential to fetch the stored credentials.

My problem is that it is returning null, and I can't seem to find any good explanation on what proposedCredential actually does and why it isn't returning what I think it should.

This is what I'm doing:

First I define a NSURLProtectionSpace, give credentials and store them in the NSURLCredentialStorage. I've already checked that this is being done before I'm referencing proposedCredential and that the credentials that I'm passing on 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];

}

Could someone tell me what proposedCredential actually does, what it compares together to figure out if there is a credential that it should pass on, and what it is that I'm possibly missing from the code?

For reference, I've been reading the Apple doc, specifically this, this, and this

All help would be appreciated.

Face answered 20/7, 2012 at 11:45 Comment(2)
Hi, I wonder if you already managed to understand the meaning of proposedCrednetials and where does it comes from. I got this callback when using proxy with credentials (whereas the credentials already defined in the system proxy), but the proposed credentials was also null. so if you've found anything, please share :-)Credent
@Credent sadly I was never able to figure this one out. Shortly after posting this question I moved on from iOS and haven't looked back.Face

© 2022 - 2024 — McMap. All rights reserved.