Friday, March 15, 2024
HomeiOS Developmentios - URLSession implementing URLSessionDelegate to bypass any certificates verification

ios – URLSession implementing URLSessionDelegate to bypass any certificates verification


I’ve an iOS framework that could be a networking module. I have to bypass certificates, however each answer I discover is all the time based mostly on this one, which did not work for my scenario.

extension FCSession: URLSessionDelegate {
    func urlSession(_ session: URLSession, didReceive problem: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        
        change problem.protectionSpace.authenticationMethod {
        case NSURLAuthenticationMethodServerTrust:
            if let serverTrust = problem.protectionSpace.serverTrust {
                let credential = URLCredential(belief: serverTrust)
                
                completionHandler(.useCredential, credential)
            }
        default:
            completionHandler(.rejectProtectionSpace, nil)
        }
    }
}

That is log of error:

Error Area=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a safe connection to the server can't be made." UserInfo={NSLocalizedRecoverySuggestion=Would you want to hook up with the server anyway?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x10880ac00)

I’ve already tried passing the completionHandler straight with the serverTrust, and receives a identical end result error.

completionHandler(.useCredential, URLCredential(belief: problem.protectionSpace.serverTrust!))



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments