Swift - The certificate for this server is invalid

SwiftiSwift picture SwiftiSwift · May 13, 2019 · Viewed 10.1k times · Source

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.

Answer

Enrique picture Enrique · Jan 9, 2020

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