How to fix ‘TIC SSL Trust Error’ in iOS?

后端 未结 5 560
星月不相逢
星月不相逢 2021-01-12 11:34

When I tried to login to the application using a webservice. I also set my plist-file like the following

I got the following error. This error

5条回答
  •  盖世英雄少女心
    2021-01-12 12:18

    Swift 5.1

    Your class has to comply with URLSessionDelegate and implement the "didReceive Challenge" function.

    These Apple Developer pages illustrates the issue and provides a lot of insight on how to securely fix this issue:

    Handling an Authentication Challenge

    Performing Manual Server Trust Authentication

    Here is an example of how to fix this issue for Dev or QA environments:

    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        #if DEBUG
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
            if challenge.protectionSpace.host == "YourTrustedDevOrQaDomain" {
                // At this point you can prevent a domain that is pretending to be a trusted domain by challenging the user to present some credentials or a security mechanism for authentication. 
                if let serverTrust = challenge.protectionSpace.serverTrust {
                    let credential = URLCredential(trust: serverTrust)
                    completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
                }
            }
        }
        #endif
    }
    

提交回复
热议问题