微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift 4 TIC SSL信任错误

@H_502_0@
@H_502_0@
我编写了这个例子但使用另一台服务器.

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)
        }
    }
@H_502_0@

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐