iosnsurlconnectionnsurlerrordomain

NSURLConnection Error code (-1202,1012)


I am using NSURLConnection for one field service type iOS appliation, so app is field service type there are more then 50 users and more then 50 users may use the application on same time that's why there are more then 50 or 60 request come to the server. Now my issue is I have received below two errors frequently means every single user can face this error more then 5 times in one day. so it become a challenge for me.

The Error Code:

-1202 NSURLErrorServerCertificateUntrusted

-1012 NSURLErrorUserCancelledAuthentication

I have searched a lot and i found that they are server related errors but still i don't have any solution for how to resolve this problem.

Please help me how can i solve this NSURLConnection error (-1202 NSURLErrorServerCertificateUntrusted and -1012 NSURLErrorUserCancelledAuthentication) problem.

Thanks in advance.


Solution

  • You need to use connectionWithRequest:delegate: to accept untrusted certificates.

    You can implement these delegate methods

    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
    {
        return YES;
    }
    
    - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
    {
        return YES;
    }