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

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

假设我的域名是example.com。


当前回答

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

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

其他回答

在Swift 5中,我们有两种方法来解决这个问题。我们需要在info.plist中添加NSAppTransportSecurity

我给出了info.plist源代码和图片以供参考

第一个是在info.plist中添加NSAppTransportSecurity->NSAllowsArbitraryLoads。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
    </dict>
</dict>
</plist>

另一种方法是在info.plist中添加NSAppTransportSecurity->NSExceptionDomains,并添加URL的域,并启用加载子域(NSIncludesSubdomains)和允许不安全HTTP加载(NSExceptionAllowsInsecureHTTPLoads)的权限

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>www.7timer.info</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
      </dict>
    </dict>
  </dict>
</plist>

有两种解决方案:

解决方案1:

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

Plist结构应如下图所示。

解决方案2:

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

Plist结构应如下图所示。

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

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

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

正如许多人所指出的,这是iOS 9.0附带的一个功能问题。他们添加了一个叫做应用程序传输安全的东西,当它破坏了我的应用程序时,我也很生气。

您可以在.plist文件中的NSAppTransportSecurity字典下使用NSAllowsArbitraryLoads键将其绑定为YES,但最终您需要重新编写形成URL的代码以形成HTTPS://前缀。

苹果在iOS 9.0中重新编写了NSUrlConnection类。您可以在NSURLConnection中了解它。

否则,您可能必须退出iOS 9.0,直到有时间实施正确的解决方案。

使用NSAppTransportSecurity:

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