我之前尝试过所有以前的答案,但没有一个对我有用。我也许知道问题所在,而且我猜错是误导了。我正在尝试向https是但没有SSL的服务器发出api请求。API也只能通过VPN运作。因此,我禁用了SSL验证,除了真正的iOS设备以外,它在其他任何地方(在模拟器,邮递员,android,mac中)都能正常运行。
到目前为止,我得到的是:
在我看来,该错误从字面上似乎是我的代码或某些逻辑而必须在iOS上完成才能在安全性上实际在实际设备上运行(如果存在)。
因此,在这里,我将分享使它到目前为止在模拟器上都能运行的实现(在此之前,我在模拟器上遇到相同的错误)。
我已将URLSessionDelegate实现到路由器类,并允许在info.plist中进行任意加载。因此,所有这些都是正确的网址,请求等。
委托不会在真实设备上被调用。
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
Run Code Online (Sandbox Code Playgroud)
提出要求之前:
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config, delegate: self, delegateQueue: .main)
Run Code Online (Sandbox Code Playgroud)
信息plist文件内容
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>*my.domain*.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
控制台错误:
[] nw_proxy_resolver_create_parsed_array PAC evaluation error:
NSURLErrorDomain: -1003
2018-06-26 20:12:08.646042+0530 MyApp[806:161960] TIC TCP Conn Failed [1:0x1c416f000]: 12:8 Err(-65554)
2018-06-26 20:12:08.646740+0530 MyApp[806:161964] Task <DCE45907-5758-4CC0-91A1-9EFD53FFDA0A>.<1> HTTP …Run Code Online (Sandbox Code Playgroud)