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

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

假设我的域名是example.com。


当前回答

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

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

有两种解决方案:

解决方案1:

在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个关键字为“允许任意加载”的元素

Plist结构应如下图所示。

解决方案2:

在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个键为“NSExceptionDomains”的元素添加具有NSDictionary类型的键“MyDomainName.com”的元素添加具有布尔类型的键“NSIncludesSubdomains”且值设置为YES的元素添加具有Boolean类型的键“NSTemporaryExceptionAllowsInsecureHTTPLoads”且值设置为YES的元素

Plist结构应如下图所示。

首选解决方案2,因为它只允许选定的域,而解决方案1允许所有不安全的HTTP连接。

使用NSAppTransportSecurity:

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

Use:

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

2015-09-25(2015-09-18 Xcode更新后):

我用了一种非懒惰的方法,但没有奏效。以下是我的尝试。

第一

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>www.xxx.yyy.zzz</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

其次,

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>www.xxx.yyy.zzz</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

最后,我使用了懒惰的方法:

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

这可能有点不安全,但我找不到其他解决方案。