The Miotz The Miotz - 1 year ago 107
Swift Question

iOS swift: App Transport Security has blocked a cleartext HTTP (http://) resource

Evening, I'm working on an app based on the SWAPI (Star Wars api:

And I got the ATS Error:

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.

I can't understand the reason. My
is on https format

struct NetworkManager {
let baseURL = ""
let session = URLSession(configuration: .default)

func fetchEndpoint(endpoint: Endpoint, completion: @escaping (_ response: Result) -> Void) {
self.fetchURL(url: baseURL + endpoint.URL(), completion: completion)

func fetchURL(url: String, completion: @escaping (_ response: Result) -> Void) {
let url = URL(string: url)!

let request = URLRequest(url: url)

let task = session.dataTask(with: request) { data, response, error in
if error != nil {
} else {
if let data = data {
if let json = try? JSONSerialization.jsonObject(with: data, options: []) {

switch json {
case let objectResponse as JSONArray: completion(.Success(objectResponse as AnyObject?))
case let objectResponse as JSONDict: completion(.Success(objectResponse as AnyObject?))
default: break


Please give me and hint!!
I'm just a newbie, and I'm guessing that the SWAPI supports only the http protocol.

Answer Source

Seems to be that you are right, that SWAPI supports only the http protocol.

To support also an unsecure connection do this:

  1. Open the info.plist file
  2. Add the Key called App Transport Security Settings as Dictionary (Dictionary should be the default type)
  3. Add the Subkey called Allow Arbitrary Loads as Boolean (Boolean should be the default type). Set it to YES

See also the Screenshot:

enter image description here

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