Steaphann Steaphann - 5 months ago 23
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=https://81.82.219.213:8080/TechAppService/TechAppService.svc//authuser?login=***&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

Step-1

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

enter image description here

Step-2

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

<key>NSAppTransportSecurity</key>
 <dict>
      <key>NSAllowsArbitraryLoads</key>
     <true/>
 </dict>

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

Comments