Heyy,我已经花了大约一天左右尝试并且未能禁用ATS,我知道它也被认为是坏的,但我目前只在内部处理应用程序。我在网上尝试了很多建议无济于事,最新尝试下面的info.plist。我迷路了怎么办?
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</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>
</dict>
</plist>
调试控制台错误打印
error = Optional(错误域= NSURLErrorDomain代码= -1022“资源 无法加载,因为App Transport Security策略需要 使用安全连接。“ UserInfo = {NSUnderlyingError = 0x7f9670e85620 {错误 Domain = kCFErrorDomainCFNetwork Code = -1022“(null)”}, NSErrorFailingURLStringKey = http://localhost/sfc/manualorder.php, NSErrorFailingURLKey = http://localhost/sfc/manualorder.php, NSLocalizedDescription =无法加载资源,因为 应用程序传输安全策略要求使用安全 连接。})
答案 0 :(得分:5)
如果要禁用ATS,只需将其添加到Info.plist
即可<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
当您完成应用程序的处理后,您可以重新启用它,并将您的域名列入白名单。
像这样,第一个包含所有子域,第二个不包括:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>maindomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>other.domain.net</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
如果您在模拟器上进行测试,可能需要增加的一个步骤是清理项目并重置模拟器的内容和设置,然后再构建并运行。