Getting NSURL Error -1012 in NSURL Request

Hi All,


I am creating the iOS app that uses rest API's that is hosted on HTTPS. This domain have valid CA approved certificate for SSL and TLS. But when I make a NSURL request from my app it works fine first time but after half an hour when I will make NSURL Request it returns NSURL Error -1012.

I also tried to handle Authentication Challenges and TLS Chain Validation using the below mentioned methods:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge


The process I used that is mentioned on below link:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html#//apple_ref/doc/uid/TP40009507-SW3

When I debug the canAuthenticateAgainstProtectionSpace and checked the protectionspace value it displays request have NSURLAuthenticationMethodServerTrust problem.

I tried different different scenarios to handle the problem.

1. In canAuthenticateAgainstProtectionSpace method if I found NSURLAuthenticationMethodServerTrust validation then I returned NO, then didReceiveAuthenticationChallenge method never called but API returns blank string.

2. In canAuthenticateAgainstProtectionSpace method if I found NSURLAuthenticationMethodServerTrust validation then I returned YES, then didReceiveAuthenticationChallenge method called and when I used continueWithoutCredentialForAuthenticationChallenge, performDefaultHandlingForAuthenticationChallenge and cancelAuthenticationChallenge methods one by one but nothing happening always I am getting the same result blank string and on cancelAuthenticationChallenge I am getting the NSURL Error -1012.

Our API is hosted on http://uat-exchange.vrmco.com/

Please help me what I am missing or is any thing that we need to used to resolve this error.


Thanks in Advance.

When you have the URLSession:didReceiveAuthenticaitonChallenge: method called for a NSURLAuthenticationMethodServerTrust challenge, you are expected to determine whether you trust the cert that the server presented to you when you conected to it. By answering NO from it you told your app to not trust it. Similiarly doing continueWithoutCredentialForAuthenticationChallenge you are also telling it you don't trust the server. Both would prevent your app from sending a request and receiving the response as you would wish. Do a search on URLSession:ddiReceiveAuthenticationChallenge and you should find a bunch of examples that show how to continue with the proper credential for the NSURLAuthenticationMethodServerTrust after properly validating the cert.

Sorry, had the old method name. Should be URLSession:didReceiveChallenge:... instead.

Getting NSURL Error -1012 in NSURL Request
 
 
Q