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

即使在plist文件上添加了临时异常,HTTP加载在xcode版本9.3 ios 11中仍失败,ios,swift,xcode,http,nsurlconnection,Ios,Swift,Xcode,Http,Nsurlconnection,我用的是swift。我看到了类似的情况,但没有答案,但这就是使用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

我用的是swift。我看到了类似的情况,但没有答案,但这就是使用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 
TIC SSL信任错误[1:0x1c4168340]:3:0
NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9843)
任务HTTP加载失败(错误代码:-1202[3:-9843])
任务已完成,但出现错误-代码:-1202
错误
屏幕截图

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 

以下是Swift中链接答案的代码。嗯

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

我正在使用swift,而且我是新手,所以我不知道如何以及在哪里实现它