我收到以下错误:Error Domain=NSURLErrorDomain Code=-1202“此服务器的证书无效。您可能正在连接到伪装成“api.linkedin.com”的服务器,这可能会使您的机密信息面临风险。” 用户信息=0x1c53e630
这在模拟器上工作正常,但在设备上它给出了上述错误。
请帮忙改正。
需要更改日期和时间的设备设置,并在当前时区自动设置为ON。
试试这个代码:
- (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];
}
希望它有帮助