有人用过iOS 9 beta 1吗?

我使用标准的NSURLConnection连接到一个webservice,一旦调用到webservice,我就会得到下面的错误。目前在iOS 8.3中运行

可能是测试版bug?任何想法都很好!我知道这是在iOS 9开发的早期

以下是完整的错误:

CFNetwork SSLHandshake失败(-9824) NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL, -9824)

 NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://mywebserviceurl"]];
        NSURLResponse * response = nil;
        NSError * error = nil;
        NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
                                                  returningResponse:&response
                                                              error:&error];

当前回答

在iOS 10+中,TLS字符串必须是“TLSv1.0”的形式。它不能只是“1.0”。(叹息)


下面是其他答案的组合。

假设您正在尝试连接到仅具有TLS 1.0的主机(YOUR_HOST.COM)。

将这些添加到应用程序的Info.plist中

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOUR_HOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

其他回答

iOS 9和OSX 10.11要求所有你计划请求数据的主机使用TLSv1.2 SSL,除非你在应用程序的信息中指定了例外域。plist文件。

Info的语法。Plist配置如下所示:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow insecure HTTP requests-->
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

如果你的应用程序(例如第三方web浏览器)需要连接到任意主机,你可以这样配置:

<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

如果您不得不这样做,最好更新您的服务器以使用TLSv1.2和SSL,如果它们还没有这样做的话。这应该被认为是一个临时的解决办法。

到今天为止,预发布文档没有以任何特定的方式提到任何这些配置选项。一旦完成,我将更新答案以链接到相关文档。

在iOS 10+中,TLS字符串必须是“TLSv1.0”的形式。它不能只是“1.0”。(叹息)


下面是其他答案的组合。

假设您正在尝试连接到仅具有TLS 1.0的主机(YOUR_HOST.COM)。

将这些添加到应用程序的Info.plist中

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOUR_HOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

在项目的.plist文件中添加以下权限:

<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Info的语法。plist配置

   <key>NSAppTransportSecurity</key>
   <dict>
   <key>NSExceptionDomains</key>
    <dict>
    <key>yourserver.com</key>
   <dict>
  <!--Include to allow subdomains-->
  <key>NSIncludesSubdomains</key>
  <true/>
  <!--Include to allow insecure HTTP requests-->
  <key>NSExceptionAllowsInsecureHTTPLoads</key>
  <true/>
  <!--Include to specify minimum TLS version-->
  <key>NSExceptionMinimumTLSVersion</key>
  <string>TLSv1.1</string>
   </dict>
 </dict>

在经历了两天的尝试和失败后,对我有效的是这个子宫代码

有一个变化,根据这篇文章,我们应该停止使用与那种惯例的NSExceptionDomains字典相关联的子键

  NSTemporaryExceptionMinimumTLSVersion

并在新的大会上使用

  NSExceptionMinimumTLSVersion

代替。

苹果公司的文档

我的代码

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>YOUR_HOST.COM</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>