根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
当前回答
iOS 9.0或更高版本提供传输安全。尝试在应用程序中调用WS时可能会出现以下警告:
应用程序传输安全性已阻止明文HTTP(HTTP://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时异常。
将以下内容添加到Info.plist将禁用ATS:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
其他回答
iOS 9.0或更高版本提供传输安全。尝试在应用程序中调用WS时可能会出现以下警告:
应用程序传输安全性已阻止明文HTTP(HTTP://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时异常。
将以下内容添加到Info.plist将禁用ATS:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
**终于!!!已解决的应用程序传输安全**
1. Follow the follow the screen shot. Do it in Targets info Section.
2015-09-25(2015-09-18 Xcode更新后):
我用了一种非懒惰的方法,但没有奏效。以下是我的尝试。
第一
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.xxx.yyy.zzz</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
其次,
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.xxx.yyy.zzz</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
最后,我使用了懒惰的方法:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
这可能有点不安全,但我找不到其他解决方案。
使用NSExceptionDomains可能不会同时应用效果,因为目标站点可能会通过http从外部域加载资源(例如js文件)。它也可以通过将这些外部域添加到NSExceptionDomains来解决。
若要检查哪些资源无法加载,请尝试使用远程调试。这里有一个教程:http://geeklearning.io/apache-cordova-and-remote-debugging-on-ios/
对于Cordova,如果您想将其添加到ios.json中,请执行以下操作:
"NSAppTransportSecurity": [
{
"xml": "<dict><key>NSAllowsArbitraryLoads</key><true /></dict>"
}
]
并且它应该位于:
"*-Info.plist": {
"parents": {
}
}