根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?

传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。

假设我的域名是example.com。


当前回答

请参阅论坛帖子应用程序传输安全?。

例如,您可以添加特定域,如:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>example.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>

懒惰选项是:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

###注:

info.plist是一个XML文件,因此您可以将这些代码或多或少地放在文件中的任何位置。

其他回答

**终于!!!已解决的应用程序传输安全**

  1. Follow the follow the screen shot. Do it in Targets info Section.

请参阅论坛帖子应用程序传输安全?。

例如,您可以添加特定域,如:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>example.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>

懒惰选项是:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

###注:

info.plist是一个XML文件,因此您可以将这些代码或多或少地放在文件中的任何位置。

使用NSAppTransportSecurity:

您必须在info.plist文件中的NSAppsTransportSecurity字典下将NSAllowsArbitraryLoads键设置为YES。

也许值得一提的是如何到达那里。。。

Info.plist是Main.storyboard或viewController.swift下面的文件之一。

当您第一次单击它时,它通常是表格格式的,因此右键单击该文件并“打开为”源代码,然后将下面的代码添加到末尾,即:

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

复制粘贴代码

 "</dict>
</plist>"

这是在最后。

根据苹果的说法,通常禁用ATS会导致应用程序被拒绝,除非你有充分的理由这样做。即使如此,你也应该为可以安全访问的域添加例外。

苹果有一个很好的工具,它可以准确地告诉你要使用什么设置:在终端中,输入

/usr/bin/nscurl --ats-diagnostics --verbose https://www.example.com/whatever

和nscurl将检查此请求是否失败,然后尝试各种设置,并告诉您通过的是哪一个,以及要做什么。例如,对于我访问的某个第三方URL,此命令告诉我此字典通过了:

{
    NSExceptionDomains = {
        "www.example.com" = {
            NSExceptionRequiresForwardSecrecy = false;
        };
    };
}

要区分您自己的站点和您无法控制的第三方站点,请使用例如键NSThirdPartyExceptionRequiresForwardSecrecy。