【发布时间】:2021-08-17 10:06:35
【问题描述】:
根据我的要求,我不应该Allow Arbitrary Loads = true。所以我设置为false。
我允许我的 URLsession 委托上的信任证书。
我的网址:https://sample-app.10.names.io
代码:
public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
//Trust the certificate even if not valid
let urlCredential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
completionHandler(.useCredential, urlCredential)
}
我的错误:
Code=-1200 "发生 SSL 错误,无法与服务器建立安全连接。" UserInfo={NSLocalizedRecoverySuggestion=您还是要连接到服务器吗?,
如果我使 Allow Arbitrary Loads = true,那么只有它可以工作。但根据我的要求,我不应该更改为 true。任何建议都会有所帮助。
谢谢
更新:
我也在下面尝试过:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>https://sample-app.10.names.io</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>
【问题讨论】:
标签: ios swift iphone xcode ssl