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

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

假设我的域名是example.com。


当前回答

对于Cordova,如果您想将其添加到ios.json中,请执行以下操作:

"NSAppTransportSecurity": [
   {
      "xml": "<dict><key>NSAllowsArbitraryLoads</key><true /></dict>"
   }
]

并且它应该位于:

"*-Info.plist": {
   "parents": {
   }
}

其他回答

如果您使用的是Xcode 8.0+和Swift 2.2+,甚至是Objective C:

如果要允许到任何站点的HTTP连接,可以使用以下键:

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

如果您知道要连接到哪些域,请添加:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

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

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

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

默认情况下,iOS仅允许HTTPS API。由于HTTP不安全,您必须禁用应用程序传输安全性。有两种禁用ATS的方法:-

1.在项目info.plist中添加源代码,并在根标记中添加以下代码。

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

2.使用项目信息。

单击左侧窗格中项目上的项目,选择项目作为目标,然后选择信息选项卡。您必须按照以下结构添加字典。

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

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

更新Xcode 7.1,面临问题27.10.15:

Info.plist中的新值是“App Transport Security Settings”。从此,本词典应包含:

允许任意加载=是例外域(在此处插入您的http域)