WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SwiftUI development against webapi on local machine causing Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid"

Forums > SwiftUI

I am trying to develop apis on my local machine which are consumed by my SwiftUI application. I followed your https://www.youtube.com/watch?v=MBCX1atOvdA video on calling an API, but when I try to call the one on my own machine I get an error:

Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost” which could put your confidential information at risk." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway

My webapi works, as I can run it and see results in the browser using local host (I have also tried w/IP as well and it works).

I have followed a number of instructions to try and ensure my simulator can connect to the API including:

  • Exporting certificate from Keychain and dragging it into the simulator
  • Adding a variety of settings to Info.plist under NSAppTransportSecurity (NSAllowArbitraryLoads, NSAllowsLocalNetworking, NSAllowsArbitraryLoads, NSExceptionDomains)

Is there any chance you could do a video on this? I have seen a lot of posts and a lot of confusion.


I could use some help with this too, actually I am not even looking for a good productive solution but just for a development solution.

I found a great API of Philips Hue and love to use this to see if I can create an app which uses this API data to control my lights. I just want to get more knowledge on implementing SwiftUI and don't want to dive into SSL Certificate issues right now. The Hue developer guide explains how you can start with PostMan by temporary disabling ssl through the property "disable ‘SSL certificate verification".

I understand that I should provide a real fix when I want to ship the app but for now I just want to play with the API so if anyone knows if there is an way to ignore the SSL errors then I would be really happy :P


Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.