出于测试目的,该项目使用自签名证书,作为网络请求的捆绑资源加载。
它适用于 Xcode8 + iOS10 设备和模拟器。
在 Xcode9和iOS 11 上,提示错误为:
----------------
<APIClient.swift> call [#77]
Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x1c0111f70>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, NSErrorPeerCertificateChainKey=(
"<cert(0x1070fb600) s: *.ABC i:ABC>",
"<cert(0x1070fce00) s:ABC i: 2048 offline root>",
"<cert(0x1070fd600) s: 2048 offline root i: 2048 offline root>"
), NSUnderlyingError=0x1c465e180 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x1c0111f70>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
"<cert(0x1070fb600) s: *.ABC i:ABC>",
"<cert(0x1070fce00) s:ABC i: 2048 offline root>",
"<cert(0x1070fd600) s: 2048 offline root i: 2048 offline root>"
)}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https:/
----------------
可以通过添加:
来解决<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我想知道它是否是模拟器错误,或安全策略是否已更改,如iOS 11上完全禁止自签名证书? 如果是,是否有链接/文档参考?