2015-10-28 93 views
1

我试图连接到iOS 9.1上的自签名HTTPS服务器。iOS应用程序传输安全性例外不起作用

我使用:

[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]; 

我也得到一个错误,指出该证书是无效的:

Error Domain=NSURLErrorDomain Code=-1202 "<French error saying the certificate is invalid" 
UserInfo= 
    {NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x13c768140>, 
    NSLocalizedRecoverySuggestion=<French recovery suggestion asking if the user wants to connect anyway>, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=<CFArray 0x13d82ffe0 [0x1a1242b68]> 

我试图将所有可能的运输安全例外,我现在的尝试是:

<key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>mydomain.org</key> 
      <dict> 
       <key>NSExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
       <key>NSExceptionRequiresForwardSecrecy</key> 
       <false/> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
      </dict> 
     </dict> 
    </dict> 

我也试过NSAllowsArbitraryLoads但即使这样也行不通。 我有几个.plist文件(cocoapods和测试),我认为它是在正确的(App/Supporting Files/Info.plist)。

有什么想法可能是错的?

回答

1

您需要在年底这样

<array> 
    <string>UIInterfaceOrientationPortrait</string> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
    <string>UIInterfaceOrientationLandscapeRight</string> 
</array> 
<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 

+1

我试过这个,但没有奏效。 – Julien

0

添加此所以这是一个NSURLConnection的问题,而不是应用程序传输。

对于记录,并为那些谁可能面临同样的问题,我已经通过调用私有方法暂时固定它(不这样做):

+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host; 

这不会被Apple接受。真正的解决方案是delegate methods,我会在编写这个答案时(我的客户是一个“开发人员”,所以我使用了他的选择,他说我们会在以后找出答案,而且我们很着急...)

0

我曾尝试使用以下步骤

解决的问题
  1. 打开项目的plist文件
  2. 添加键“NSAppTransportSecurity”和型词典
  3. 添加内部密钥“NSAllowsArbitraryLoads”布尔是

enter image description here

相关问题