Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSAllowsArbitraryLoads not working

I had a working app that downloads some info from an http domain. But after the Swift 2.0 and Xcode 7 update, my app can't connect to the server and download the json data, I get the "App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." error.

I have tried putting this lines in my info.plist:

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

But I get the same error, it's not working. I always get nil data from the download methods. Any one has this same error? Thanks!

EDIT: Here is a picture from my info.plist file:

Info.plist file

like image 402
Pablo Quemé Avatar asked Oct 05 '15 14:10

Pablo Quemé


People also ask

What is Nsallowsarbitraryloads?

A Boolean value indicating whether App Transport Security restrictions are disabled for all network connections.

What is Nsexceptiondomains?

Discussion. The value for this key is a dictionary with keys that name specific domains for which you want to set exceptions. The value for each domain key is another dictionary that indicates the exceptions for that domain.


2 Answers

I feel so stupid. I added the keys for disabling the ATS on the wrong Info.plist. Instead of adding it in the Supporting Files/Info.plist file, I added it on MyAppTests/Supporting Files/Info.plist file. Not really a bug in Xcode, but a bug in my brain. Thank you all for your answers!

like image 136
Pablo Quemé Avatar answered Sep 27 '22 20:09

Pablo Quemé


You can try using

nscurl --ats-diagnostics <your-URL>

in the terminal. This can help you find the settings that will allow your app to connect to your-URL. This only works on OSX El Capitan. Check out the apple technote.

But if you've tried NSArbitraryLoads in your info.plist file, this diagnostic tool probably won't help you. I think you might have found a bug.

like image 25
simple_code Avatar answered Sep 27 '22 22:09

simple_code