Swift - The certificate for this server is invalid

16,003

Solution 1

You just need to install the certificates on the iOS simulators


From Charles Documentation:

Quit your iOS Simulator. Launch Charles and go to the Help menu. Choose the "SSL Proxying > Install Charles Root Certificate in iOS Simulators" item. This will install your Charles Root Certificate into all of your iOS Simulators. Now when you start the iOS Simulator, you should be able to access SSL websites with Charles using SSL Proxyin

Solution 2

You are most probably trying to connect to server with self-signed ssl certificate. iOS does not like it. Take a look at this post as an example: Swift SSL error with self signed certificate. Other possible issue is a proxy configuration with something like Charles behind it. More details will maybe help to identify the root of the issue...

Share:
16,003
SwiftiSwift
Author by

SwiftiSwift

Updated on June 18, 2022

Comments

  • SwiftiSwift
    SwiftiSwift almost 2 years

    How can I fix this on iOS using Swift? When I'm making a server request I get the following error:

    The certificate for this server is invalid. You might be connecting to a server that is pretending to be “...” which could put your confidential information at risk.

  • Bagusflyer
    Bagusflyer over 4 years
    My app is running fine until the iOS 13. I got this error when testing with iOS 13. Any suggestion? Is there anyway to bypass this error because I can't touch the server certificate now.
  • Ariel
    Ariel over 4 years
    You can try to implement func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) method of the URLSessionDelegate overriding default behaviour.
  • Bagusflyer
    Bagusflyer over 4 years
    I'm using Alamofire to call rest api. Is there a way to bypass this error? Thanks.
  • Deepak Bradly
    Deepak Bradly almost 4 years
    Wonderful.!! Thank you
  • sarah
    sarah over 3 years
    @Bagusflyer do you find the solution?