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

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

假设我的域名是example.com。


当前回答

Use:

在类型为Dictionary的plist文件中添加新项NSAppTransportSecurity,然后在类型为Boolean的字典中添加子项NSAllowsArbitraryLoads,并设置bool值YES。这对我有用。

其他回答

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

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

<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文件,因此您可以将这些代码或多或少地放在文件中的任何位置。

我不喜欢直接编辑plist。您可以使用GUI轻松地将其添加到plist:

单击左侧导航器中的Info.plist。现在更改主区域中的数据:在最后一行添加+输入组的名称:应用程序传输安全设置右键单击组并选择“添加行”输入允许任意加载将右侧的值设置为YES

开发示例

这里是一个plist的截图,它保持ATS的完整性(=安全),但允许通过HTTP而不是HTTPS连接到本地主机。它在Xcode 7.1.1中工作。

如本技术说明所述,确定可以自动执行哪些设置:

/usr/bin/nscurl --ats-diagnostics --verbose https://your-domain.com

在swift 4和xocde 10中,将NSAllowsArbitraryLoads更改为允许任意加载。所以它将是这样的:

<key>App Transport Security Settings</key>
<dict>
     <key>Allow Arbitrary Loads</key><true/>
</dict>