ios - 即使在 plist 文件上添加临时异常后,在 xcode 版本 9.3 ios 11 中 HTTP 加载失败

标签 ios swift xcode http nsurlconnection

我正在使用 swift。我看到了类似的 question但没有答案和another但那是使用 objective c 语言。

错误日志:

TIC SSL Trust Error [1:0x1c4168340]: 3:0

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)

Task <00FBDA7D-E906-4BE2-8862-0AD6CAF1A0D7>.<1> HTTP load failed (error code: -1202 [3:-9843])

Task <00FBDA7D-E906-4BE2-8862-0AD6CAF1A0D7>.<1> finished with error - code: -1202
error 

截图:

screenshot of plist file

最佳答案

这是来自 Swift 中链接答案的代码。 HTH.

class RequestHelper: NSObject, URLSessionDelegate {
    func makeRequest(request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) ->() ) {
        let sessionConfiguration = URLSessionConfiguration.default
        let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
        let task = session.dataTask(with: request) { data, response, error in
            completionHandler(data, response, error)
        }
        task.resume()
    }

    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition,
        URLCredential?) -> () ) {
        guard
            challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
            challenge.protectionSpace.host == "yourdomain.com",
            let trust = challenge.protectionSpace.serverTrust
        else {
            return
        }
        let credential = URLCredential(trust: trust)
        completionHandler(.useCredential, credential)
    }
}

关于ios - 即使在 plist 文件上添加临时异常后,在 xcode 版本 9.3 ios 11 中 HTTP 加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50226246/

相关文章:

ios - 最低操作系统版本不匹配

ios - 删除可选的 Alamofire(以及任何地方)

ios - 创建一个可以快速交互的不可见 View

swift - 在 for 循环中的 Mapbox 中添加自定义标记

ios - 当具有不同值的同一类对象作为数据源传递时,为什么不重新呈现 View

objective-c - 自动修复 "direct comparison of a string literal has undefined behavior"

iOS - 防止点击 UIButton 传播到其后面的 View

iphone - 使用 GData XML 构建 iPhone 应用程序失败 : undefined symbols (for architecture i386)

ios - 在Combine iOS 中获取我的订阅取消状态

arrays - 如何使用 Swift 访问本地主机上的 JSON 数组?