Friday, September 19, 2014

NSURLAuthenticationChallenge


#pragma mark - NSURLConnection delegate for Handling HTTPS
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {
  NSLog(@"Authentication String : %@", NSURLAuthenticationMethodServerTrust);
 
  NSLog(@"protectionSpace.authenticationMethod : %@", protectionSpace.authenticationMethod);
 
  //return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
 
  return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
 
  NSLog(@"challenge.protectionSpace.authenticationMethod : %@", challenge.protectionSpace.authenticationMethod);
 
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    NSLog(@"************ CERTIFICATE DOWNLOADED ***************");
  }
  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
 
}

No comments: