iOS App Transport Security问题

时间:2015-10-07 18:57:04

标签: ios xcode web-services nsurlconnection app-transport-security

TL; DR:

我有一个iOS应用程序连接到满足新ATS功能的最低要求的Web服务。我修改了Info.plist以允许例外,因此我的应用仍然可以连接到网络服务。 (NSURLSession/NSURLConnection HTTP load failed on iOS 9)这在开发中可以正常工作,但是,我刚刚推送到商店的更新仍无法访问网络服务。我不知道断开连接的位置或解决方法。

===

首先,这是在模拟器中发生的,当我在xcode中直接部署到我的ipad时会出现相同的行为:

我正在尝试通过iOS应用中的https连接到网络服务。我每次尝试连接到webservice时都会收到此错误:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

我的理解是,这种情况正在发生,因为新的ATS功能不允许连接。我已通过将修复程序(NSURLSession/NSURLConnection HTTP load failed on iOS 9)应用于我的Info.plist文件来确认这一点:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>mydomain.com</key>
    <dict>
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <key>NSIncludesSubdomains</key>
      <true/>
      </dict>
  </dict>
</dict>

一旦我把它放入,它就会毫无问题地连接到web服务。

显然,当我的服务器满足TLS 1.2要求和密码要求时,它不符合签名要求(https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35

但是,我已对我的应用程序进行了更新并推送到应用程序商店,但我的应用程序的商店版本无法连接到Web服务。在我的本地计算机上构建完全相同的代码并在从xcode部署到我的设备时运行,但是商店中的版本似乎忽略了.plist修复。 我该如何解决这个问题?这对我来说毫无意义。

2 个答案:

答案 0 :(得分:0)

尝试info.plist的此版本配置:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>www.example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

编辑:尝试同时将NSExceptionRequiresForwardSecrecy指定为NO

答案 1 :(得分:0)

尝试将以下代码添加到info.plist

<key>NSAppTransportSecurity</key>  
     <dict>  
      <key>NSAllowsArbitraryLoads<key><true/>  
     </dict>  

有关详细信息,请参阅链接:apple forum