使用 Xcode 7 测试 iOS 9 应用程序无法从 http 请求中获取数据

With Xcode 7 testing an iOS 9 app is unable to obtain data from a http request

我正在 iOS 开发应用程序。对于我的开发,我使用 Xcode beta7。之前,我曾经在更新到 iOS 9 后使用 iOS 8.4 在我的手机中测试我的应用程序,我无法在我的手机中安装相同的应用程序。请给我一些建议。非常感谢!

从最初最少的问题信息来看,问题可能是对不符合当前安全最佳实践的服务器的失败 http 请求。

iOS9 现在默认要求服务器支持带 TLS 1.2 的 https、转发安全和安全加密方法。

发件人:App Transport Security Technote

Default Behavior:
All connections using the NSURLConnection, CFURL, or NSURLSession APIs use App Transport Security default behavior in apps built for iOS 9.0 or later, and OS X 10.11 or later. Connections that do not follow the requirements will fail.

解决方案是将服务器更新为 https TLS 1.2 并转发安全性。也只支持上述Security Technote中的加密方式。

另一种解决方案是将 url 列入应用程序列表中的白名单,甚至在必要时允许所有 http 连接。这降低了连接安全性,最好的办法是更新服务器。

如有必要,可以允许所有 URL,这通常仅在不知道要访问的 URL 时才需要,可能是用户提供的或有大量已知 URL。

要禁用所有 URL 的安全性,请将此添加到应用程序的 plist 文件中:
不推荐)除非你真的需要访问未知的 URL

<key>NSAppTransportSecurity</key>  
     <dict>  
          <key>NSAllowsArbitraryLoads</key><YES/>  
     </dict>  

要禁用单个 URL(和子 URL)的安全性,请将其添加到应用程序的 plist 文件(更改 "yourdomain.com to the correct URL":

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

Apple 提供了关于这几个地方的信息:

WWDC 2015 session 706 that described as well as the release notes: What's New in iOS iOS 9.0。相信在WWDC的主题演讲中也提到了

另请参阅此 SO 答案:About ATS SSL in iOS 9 release version

确保设置 NSAppTransportSecurity 以实现兼容性。

参见:

将此行添加到您的 .plist 文件中:

来源:

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

解决方法,已编辑,因为不应使用。保护您的数据