嘿,我花了最后一天左右的时间尝试并未能禁用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(Error Domain = NSURLErrorDomain代码= -1022“资源
无法加载,因为应用程序传输安全策略要求
使用安全连接。”
UserInfo = {NSUnderlyingError = 0x7f9670e85620 {Error
Domain = kCFErrorDomainCFNetwork代码= -1022“(null)”},
NSErrorFailingURLStringKey = http://localhost/sfc/manualorder.php,
NSErrorFailingURLKey = http://localhost/sfc/manualorder.php,
NSLocalizedDescription =无法加载资源,因为
App Transport Security策略要求使用安全
连接。})
最佳答案
如果要禁用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>
如果要在模拟器上进行测试,您可能还需要增加一个步骤,即清理项目并重置模拟器的内容和设置,然后再次构建并运行。
关于ios - Xcode 7.1 beta 2-禁用ATS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32892121/