5

I am getting the following error:

Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “api.linkedin.com” which could put your confidential information at risk." UserInfo=0x1c53e630

This works fine on simulator but on device it is giving above mentioned error.

Please help to rectify it.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Sachin Siwal
  • 311
  • 1
  • 3
  • 13
  • have u tring to find this with some effort in google take a look http://stackoverflow.com/questions/3916574/i-want-to-ignore-certificate-verification-where-and-how-to-do-it-with-xmlrpc-we and http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert – Nitin Gohel Aug 24 '13 at 06:57
  • 1
    i tried above links , but not worth for me , – Sachin Siwal Aug 24 '13 at 08:50
  • I got it by losting my whole day, It was my device setting that need to change the date and time , and set it automatically ON for current time zone . – Sachin Siwal Aug 24 '13 at 10:53

2 Answers2

13

It is device setting that need to change the date and time , and set it automatically ON for current time zone .

Sachin Siwal
  • 311
  • 1
  • 3
  • 13
-2

Try this code:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([trustedHosts containsObject:challenge.protectionSpace.host])
  [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

 [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

Hope it helpful

Huy Nghia
  • 996
  • 8
  • 22
  • i have already tried it, this is throwing same error as i mentioned in question, it is working fine on simulator, this error is killing me on device only. – Sachin Siwal Aug 24 '13 at 09:38
  • 1
    Improve on this answer by explaining what the solution would fix, perhaps format for readability. – Rob van der Veer Aug 24 '13 at 09:44
  • 1
    I got it by losting my whole day, It was my device setting that need to change the date and time , nad set it automatically ON for current time zone . – Sachin Siwal Aug 24 '13 at 10:52
  • you should give credit when you copy code like [this one](http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert/2033823#2033823) – YvesLeBorg Oct 21 '16 at 21:47