Search code examples
iphonehttpsrequest3g

HTTPS request on old iphone 3g


Anyone else having issues with getting a https request working on the old iphone.

From connection did fail with error the error message is as follows.

ERROR with theConnection:Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.ourwesbite.co.uk” which could put your confidential information at risk."

The "ourwebsite" has a valid certificate and also this problem does not arise in any new iphone/ipod touch or ipads just the oldest iphones.

This is affecting my login from working by throwing a connection error after user clicks ok to the connection error alert the login process runs through fine. But the problem is its affecting the UI after the login.

So pretty much want to know if anyone else is having issues like this with the old iphone. There is no problem with my code as it works perfectly fine on simulator & ipad/4gen ipod touch.

Thanks


Solution

  • Ok so even tho the certificate is valid it will throws the error. So using the following delegate method for NSURLConnection solved this problem.

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

    it gets called when there is a challenge to the authentication. The the following bit of code allow's it to continue with the https connection.

    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    

    And then that allows the connection through if it feels it is untrusted