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

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

假设我的域名是example.com。


当前回答

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

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

其他回答

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

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

以下是直观的设置:

Use:

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

如果您使用的是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>

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

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