Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSURlerorDomain-1202仅适用于iPhone 4_Ios_Objective C_Nsurlerrordomain - Fatal编程技术网

Ios NSURlerorDomain-1202仅适用于iPhone 4

Ios NSURlerorDomain-1202仅适用于iPhone 4,ios,objective-c,nsurlerrordomain,Ios,Objective C,Nsurlerrordomain,我的应用程序,目前在苹果商店有一个登录功能。我收到了很多只使用iPhone4的客户的投诉。他们抱怨他们无法登录自己的帐户。这种情况只发生在iPhone4设备上(可能也发生在手持设备上)。该错误返回代码-1202(NSURErrorServerCertificateUntrusted)。我不明白的是,它能在任何更新的设备上工作(iPhone4S、5、5C和5S) 我知道我可以通过植入下面的行来强制应用程序信任服务器,但这不是一个有效的解决方案 - (void)connection:(NSURLCo

我的应用程序,目前在苹果商店有一个登录功能。我收到了很多只使用iPhone4的客户的投诉。他们抱怨他们无法登录自己的帐户。这种情况只发生在iPhone4设备上(可能也发生在手持设备上)。该错误返回代码-1202(NSURErrorServerCertificateUntrusted)。我不明白的是,它能在任何更新的设备上工作(iPhone4S、5、5C和5S)

我知道我可以通过植入下面的行来强制应用程序信任服务器,但这不是一个有效的解决方案

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
  [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
 {
  return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
如果我添加didReceiveAuthenticationChallenge,是否足够:

SecTrustRef trustRef = [[challenge protectionSpace] serverTrust];
SecTrustEvaluate(trustRef, NULL);
CFIndex count = SecTrustGetCertificateCount(trustRef);
if(count > 0)
{
  SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, 0);
  CFStringRef certSummary = SecCertificateCopySubjectSummary(certRef);
  NSString* certSummaryNs = (__bridge NSString*)certSummary;
  if([certSummaryNs isEqualToString:@"MY_API"])
    NSLog(@"Verified");
  else
    NSLog(@"Invalid");
}
else
  NSLog(@"No certificate found");

您是否尝试过需要更改日期和时间的设备设置,并将其自动设置为当前时区。

哪些iOS版本存在此问题?是的,我认为旧版本的iOS可能会使信任存储太过保留,从而导致请求失败。但我目前正在使用最新版本的IOS 7.1进行测试,我也遇到了同样的问题。@user1735977如果不起作用,您应该尝试此方法。请检查您的iPhone4设备中的设置时间datetime有时不为true也会出现NSURErrorServerCertificateUntrusted错误。我发现了问题所在。这不是IOS的问题。服务器上缺少某些证书。。。仍然没有解释为什么它在iphone4以外的其他设备上工作。但现在它起作用了。谢谢你们的帮助,guysHi pierre23,你们能提供一个方法,你们如何解决这个问题,因为我在iPhone4中也面临同样的问题,并没有找到任何解决方案。
SecTrustRef trustRef = [[challenge protectionSpace] serverTrust];
SecTrustEvaluate(trustRef, NULL);
CFIndex count = SecTrustGetCertificateCount(trustRef);
if(count > 0)
{
  SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, 0);
  CFStringRef certSummary = SecCertificateCopySubjectSummary(certRef);
  NSString* certSummaryNs = (__bridge NSString*)certSummary;
  if([certSummaryNs isEqualToString:@"MY_API"])
    NSLog(@"Verified");
  else
    NSLog(@"Invalid");
}
else
  NSLog(@"No certificate found");