你确定它不起作用吗?我测试了它,一切都很好。
可能的行动:
启用调试模式,构建您的应用程序,从 Xcode 运行它并确保您不会收到 App Transport Security 错误:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
使用模拟器从 Xcode 启动它时。现在找到同一个模拟器的DEVICE_CODE
(Hint: it will be one of these ~/Library/Developer/CoreSimulator/Devices/. The easiest way to find this code from Xcode is to go Window->Devices)
并使用控制台打开其日志文件:
~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log
清除历史记录(以防万一您可以再次从 Xcode 启动您的应用并确保您的输出进入您打开的日志文件,并且您仍然没有获得 App Transport Security em> 里面有错误)。
现在从模拟器启动您的应用,并检查日志中是否有任何与 App Transport Security 相关的错误。
对我来说,在使用 Xcode 工作时,如果没有,我也没有。
===================================
附言:
强烈建议不要将 NSAllowsArbitraryLoads 设置为 true,您宁愿通过以下方式获得所需的结果:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</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>