Swift - The certificate for this server is invalid
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...
SwiftiSwift
Updated on June 18, 2022Comments
-
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 over 4 yearsMy 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 over 4 yearsYou can try to implement
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
method of theURLSessionDelegate
overriding default behaviour. -
Bagusflyer over 4 yearsI'm using Alamofire to call rest api. Is there a way to bypass this error? Thanks.
-
Deepak Bradly almost 4 yearsWonderful.!! Thank you
-
sarah over 3 years@Bagusflyer do you find the solution?