0

I am getting this error in xcode "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."

The point is i am using https in my api call. I am not using http at all. But still getting this error.

I've Also added "App Transport Security Settings: Allow Arbitrary Loads: YES" in my info.plist file.

Here is code snippet:

import Foundation

enum MovieError: String, Error  {
    case responseProblem
    case decodingProblem
    case encodingProblem
}

struct NetworkManager {
    let baseURL = "https://ee15abd0abc1.ngrok.io/api"
    let url: URL
    let API_KEY = ""
    
    init(endPoint: String) {
        let resourceURL = "\(baseURL)/\(endPoint)"
        guard let url = URL(string: resourceURL) else { fatalError() }
        self.url = url
    }
    
    func login(_ login: Login, completion: @escaping(Result<LoginToken, MovieError>) -> Void) {
        
        do {
            var urlRequest = URLRequest(url: self.url)
            urlRequest.httpMethod = "POST"
            urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
            urlRequest.httpBody = try JSONEncoder().encode(login)
            
            let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
                
                guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200, let jsonData = data else {
                    completion(.failure(.responseProblem))
                    return
                }
                
                do {
                    let loginToken = try JSONDecoder().decode(LoginToken.self, from: jsonData)
                    completion(.success(loginToken))
                } catch {
                    completion(.failure(.decodingProblem))
                }
            }
            
            dataTask.resume()
        } catch {
            completion(.failure(.encodingProblem))
        }
    }
}
iamimran
  • 110
  • 2
  • 7

1 Answers1

0

You need to check these settings enter image description here

https://useyourloaf.com/blog/app-transport-security/

Dharman
  • 30,962
  • 25
  • 85
  • 135