应用传输安全策略需要使用安全连接 - IOS 9
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32712155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App Transport Security policy requires the use of a secure connection - IOS 9
提问by user831098
I'm facing problem connection to API with using IP address. Even I had add the following code to plist, it still show error as below:
我在使用 IP 地址连接到 API 时遇到问题。即使我将以下代码添加到 plist,它仍然显示如下错误:
"http://xx3.xx.xx8.xx7/xxx/xxx/error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."
“ http://xx3.xx.xx8.xx7/xxx/xxx/错误:无法加载资源,因为应用传输安全策略要求使用安全连接。”
This is the code I add to the plist
这是我添加到 plist 的代码
<key>xx3.xx.xx8.xx7</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</key>
回答by larva
Document Allowing Insecure Connection to a Single Server here. So you must add NSAppTransportSecurity
to your info.plist file in truth way like flowing (to show Info.plist in source, in Xcode right click to Info.plist "Open As"->"Source Code")
此处的文档允许与单个服务器的不安全连接。所以你必须NSAppTransportSecurity
像流动一样以真实的方式添加到你的 info.plist 文件中(在源代码中显示 Info.plist,在 Xcode 中右键单击 Info.plist “Open As”->“Source Code”)
To configure a per-domain exception:
要配置每个域的例外:
<?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>
<!--others key-->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>insecure-domain1.example.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
</dict>
<key>insecure-domain2.example.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
</dict>
</dict>
</dict>
<!--others key-->
</dict>
</plist>
after edit Infor.plist file look like following:
Or disable ATS:
或禁用 ATS:
<?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>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>