根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
当前回答
更新Xcode 7.1,面临问题27.10.15:
Info.plist中的新值是“App Transport Security Settings”。从此,本词典应包含:
允许任意加载=是例外域(在此处插入您的http域)
其他回答
请参阅论坛帖子应用程序传输安全?。
例如,您可以添加特定域,如:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>example.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>
懒惰选项是:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
###注:
info.plist是一个XML文件,因此您可以将这些代码或多或少地放在文件中的任何位置。
默认情况下,iOS仅允许HTTPS API。由于HTTP不安全,您必须禁用应用程序传输安全性。有两种禁用ATS的方法:-
1.在项目info.plist中添加源代码,并在根标记中添加以下代码。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2.使用项目信息。
单击左侧窗格中项目上的项目,选择项目作为目标,然后选择信息选项卡。您必须按照以下结构添加字典。
有两种解决方案:
解决方案1:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个关键字为“允许任意加载”的元素
Plist结构应如下图所示。
解决方案2:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个键为“NSExceptionDomains”的元素添加具有NSDictionary类型的键“MyDomainName.com”的元素添加具有布尔类型的键“NSIncludesSubdomains”且值设置为YES的元素添加具有Boolean类型的键“NSTemporaryExceptionAllowsInsecureHTTPLoads”且值设置为YES的元素
Plist结构应如下图所示。
首选解决方案2,因为它只允许选定的域,而解决方案1允许所有不安全的HTTP连接。
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>
这可能有点不安全,但我找不到其他解决方案。
更新Xcode 7.1,面临问题27.10.15:
Info.plist中的新值是“App Transport Security Settings”。从此,本词典应包含:
允许任意加载=是例外域(在此处插入您的http域)