Steaphann Steaphann - 2 years ago 127
Swift Question

Configuring NSAppTransportSecurity in code

I have an app that is used by different companies. The user first needs to log in throughout a webservice with always the same base-url. When he is logged in successfully I get a base-url (with htttps) back from the webservice. But this base-url is different for each company.

Now when I start my app in IOS9 and I log in and try to call the webservices with the different base-url, I get this error:

Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9847, NSErrorFailingURLStringKey=***&password=***

I know that I need to set up the NSAppTransportSecurity dictionary in the info.plist. The problem now is that I don't know how I can set this in code.

Answer Source


select info.plist and click Right --> go to Source Code

enter image description here


the source code open as Key Format , on that key add the following keys in last


you can see like sample output

enter image description here

Step - 3

it automatically added in your plist just like follows

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download