swift - 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?)。我在这里找到的答案仅引用NSAllowsArbitraryLoads
、NSExceptionDomains
和。还有什么?NSExceptionMinimumTLSVersion/NSTemporaryExceptionMinimumTLSVersion
NSThirdPartyExceptionRequiresForwardSecrecy
解决方案
因为您info.plist
包含NSAllowsArbitraryLoadsInWebContent
密钥,所以NSAllowsArbitraryLoads
忽略并视为错误。所以删除NSAllowsArbitraryLoadsInWebContent
应该允许所有任意负载。
Apple 文档的相关部分:
在 iOS 10 及更高版本和 macOS 10.12 及更高版本中,NSAllowsArbitraryLoads 键的值将被忽略——并且使用默认值 NO——如果您的应用程序的信息属性列表文件中存在以下任何键:
- NSAllowsArbitraryLoadsForMedia
- NSAllowsArbitraryLoadsInWebContent
- NSA允许本地网络
推荐阅读
- python - PySpark:从列的有序连接创建一列
- c++ - 通过套接字发送整数数组的问题
- c# - 如何使用 openssl 创建与 X509Certificate2 兼容的 pfx
- vba - VBA 循环遍历文件夹中的非模式文件(征求意见)[编辑]
- matplotlib - 在 Heroku 上访问我的网站
- python - 列表索引 - 如果太大返回列表的开头
- java - 使用 JavaRDD 进行 Spark 排序
- php - 将 PHP 数组转换为电子邮件的 HTML 表
- python-3.x - 使用 geopy 库时出错
- powershell - 用于获取未使用证书的 Powershell 脚本