7

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.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96

2 Answers2

6

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

Enrique
  • 1,586
  • 17
  • 14
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...

Ariel
  • 2,430
  • 1
  • 17
  • 20
  • 2
    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. – Bagusflyer Nov 06 '19 at 01:52
  • 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. – Ariel Nov 06 '19 at 07:45
  • 2
    I'm using Alamofire to call rest api. Is there a way to bypass this error? Thanks. – Bagusflyer Nov 25 '19 at 01:58
  • @Bagusflyer do you find the solution? – sarah Dec 10 '20 at 22:14