以下代码始终返回nil。
let url = NSURL(string: "https://s3.amazonaws.com/test-contentdelivery-mobilehub-462838928/tree.jpg")
let data = NSData(contentsOfURL: url!)
2015-10-31 16:25:16.795 test2[59798:19080494] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
网址已经https,aws s3提供TLS 1.2 SSL。您可以在浏览器中尝试上述URL,并检查认证和连接信息。看起来已经满足了ios 9的要求,但数据仍然没有。我不想在Info.plist中设置“允许任意加载”= YES。任何的想法?我错过了什么吗?是NSData(contentsOfURL:url!)使用http而不是https?
答案 0 :(得分:0)
他们建议在准备就绪之前定义退出规则:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>amazonaws.com.cn</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
答案 1 :(得分:0)
直到亚马逊准备就绪,你可以将以下内容放入info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>