首页 > 解决方案 > ATS 错误:“ATS 策略需要使用安全连接”,尽管 plist

问题描述

我正在尝试请求一个 http 域,尽管有

<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>my-private-domain.kubernetes.intranet%2f:9090</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

在我的应用程序目标的 info.plist 中,XCode 12.5.1 让我一直显示错误

Task <C5F9EA01-9790-43ED-89B0-EE07341B4D84>.<4> finished with error [-1022] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

我需要在更新到 12.5.1 后执行此请求,并且还尝试了清理构建文件夹并删除-重新安装应用程序。有人知道这是否是政策变化吗?(也许现在即使在非生产目标中也只允许使用 HTTPS?)。我在这里找到的答案仅引用NSAllowsArbitraryLoadsNSExceptionDomains和。还有什么?NSExceptionMinimumTLSVersion/NSTemporaryExceptionMinimumTLSVersionNSThirdPartyExceptionRequiresForwardSecrecy

标签: swiftxcode

解决方案


因为您info.plist包含NSAllowsArbitraryLoadsInWebContent密钥,所以NSAllowsArbitraryLoads忽略并视为错误。所以删除NSAllowsArbitraryLoadsInWebContent应该允许所有任意负载。

Apple 文档的相关部分:

在 iOS 10 及更高版本和 macOS 10.12 及更高版本中,NSAllowsArbitraryLoads 键的值将被忽略——并且使用默认值 NO——如果您的应用程序的信息属性列表文件中存在以下任何键:

  • NSAllowsArbitraryLoadsForMedia
  • NSAllowsArbitraryLoadsInWebContent
  • NSA允许本地网络

推荐阅读