Error Domain=NSURLErrorDomain Code=-1202 iPhone

假装没事ソ 提交于 2019-12-01 04:05:09

问题


I am geting 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.


回答1:


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




回答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



来源:https://stackoverflow.com/questions/18415157/error-domain-nsurlerrordomain-code-1202-iphone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!