加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift 4 TIC SSL信任错误

发布时间:2020-12-14 04:56:32 所属栏目:百科 来源:网络整理
导读:我编写了这个例子但使用另一台服务器. http://andrewmarinov.com/parsing-json-swift-4/ 我将收到一个Json文件,但我收到错误: TIC SSL信任错误 SURLSession / NSURLConnection HTTP加载失败 我无法改变服务器上的任何内容! 我可以在swift 4 / IOS11中使用
我编写了这个例子但使用另一台服务器.

http://andrewmarinov.com/parsing-json-swift-4/

我将收到一个Json文件,但我收到错误:
TIC SSL信任错误
SURLSession / NSURLConnection HTTP加载失败

我无法改变服务器上的任何内容!

我可以在swift 4 / IOS11中使用一些代码来修复它吗?
这是我更改的Plist:

<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

谢谢!

解决方法

我写了这段代码,他们为我工作

func urlSession(_ session: URLSession,didReceive challenge: URLAuthenticationChallenge,completionHandler: @escaping (URLSession.AuthChallengeDisposition,URLCredential?) -> Void) {
        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate) {
            completionHandler(.rejectProtectionSpace,nil)
        }
        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
            let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(.useCredential,credential)
        }
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读