0

我想在Alamofire. 这是我的代码:


            // Set up certificates
            let pathToCert = Bundle.main.path(forResource: cert, ofType: "der")
            let localCertificate = NSData(contentsOfFile: pathToCert!)
            let certificates = [SecCertificateCreateWithData(nil, localCertificate!)!]

            // Configure the trust policy manager
            let serverTrustPolicy = ServerTrustPolicy.pinCertificates(
                certificates: ServerTrustPolicy.certificates(),
                validateCertificateChain: false,
                validateHost: true)

            let serverTrustPolicies = ["hostname": serverTrustPolicy]
            let serverTrustPolicyManager = ServerTrustPolicyManager(policies: serverTrustPolicies)

            let sessionManager = SessionManager(configuration: URLSessionConfiguration.default,serverTrustPolicyManager: serverTrustPolicyManager)


            sessionManager
                .request()...

这是我的 info.plist ->

信息列表

我得到这个错误: load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled"

我搜索了很多,但找不到任何可以解决我的问题的东西。我.crt使用. .der_open ssl

4

1 回答 1

0

除了SessionManager在请求完成之前 deinit'd 时看到这个错误,就像这里的问题一样,它也是你在 Alamofire 4 中证书固定失败时会看到的。更新到 Alamofire 5 会给你一个更好的错误两种情况。

于 2019-11-27T20:19:29.347 回答