iOS9 - HTTP连接错误

Ibr*_*LAT 12 http nsurlsession

我更新我的Xcode时遇到3个错误

1- App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全.可以通过应用程序的Info.plist文件配置临时例外.

2- CFNetwork SSLHandshake失败(-9824)

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

我试过了:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourdomain.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
Run Code Online (Sandbox Code Playgroud)

<key>NSAppTransportSecurity</key>  
 <dict>  
      <key>NSAllowsArbitraryLoads</key><true/>  
 </dict>
Run Code Online (Sandbox Code Playgroud)

但他们没有工作.任何人都可以帮助我!谢谢.

小智 11

从Project Navigator中单击项目的名称. 在此输入图像描述

现在,在右侧,您将看到项目的"常规"选项卡.选择"信息"选项卡 在此输入图像描述 展开海关iOS目标属性 在此输入图像描述 添加新类型,将其命名为NSAppTransportSecurity,键入为Dictionary.It将在此文本中转换App Transport Security Settings 在此输入图像描述 在里面添加一个新项并将其命名为NSAllowsArbitraryLoads,键入为布尔值,值为YES. 在此输入图像描述

在论坛上查看此主题以获取更多详细信息,请将该条目添加到info.plist中

https://forums.developer.apple.com/message/5857#5857

并参考WWDC的Session 711. https://developer.apple.com/videos/wwdc/2015/?id=711

  • 请注意,Apple在提交到应用商店时可能会拒绝使用NSAllowsArbitratyLoads键的应用 - 除非您有充分的理由.最好使用NSExceptionDomains,并列出要从规则中免除的所有域.以下是应用程序传输安全文档的链接:https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33 (2认同)