0

I have a problem with URLSessionDataTask only on iPhone 7 with network type 4g, same device with network type WiFi runs.Can anyone help me?

This is the code in Swift 3 :

func getParentAccount(onGetParentAccountComplete: OnGetParentAccountComplete) {

    let url = URL(string: "http://...")!
    let authorizationHeader = authorizationHeaderFactory.getOAuth2Authorization()

    var request = URLRequest(url: url)
    request.setValue(authorizationHeader["Authorization"], forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Accept")
    request.httpMethod = "GET"

    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        guard let data = data, error == nil else {                                                 // check for fundamental networking error
            // error
            print("Error: \(String(describing: error))")
            onGetParentAccountComplete.onGetParentAccountFailure(message: "Communication error")
            return
        }

        if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode == 200, let json = try? JSONSerialization.jsonObject(with: data, options: []) {
            // ok
            let parentAccountDTO = self.parentAccountMapper.mapJSONToDTO(json: json as! [String : Any])
            onGetParentAccountComplete.onGetParentAccountSuccess(parentAccount: self.parentAccountMapper.mapDomain(source: parentAccountDTO))

            return
        } else {
            // error
            print("Error: response = \(String(describing: response))")
            onGetParentAccountComplete.onGetParentAccountFailure(message: "Error response")
            return
        }
    }

    task.resume()
}
ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
  • What is the exact problem you have? What is the result of the network request? Is `error` non `nil`? Or is `data` `nil`? Are other apps able to communicate through 4G on the same device? Are you sure the URL you are trying to access is not blocked by your provider? – Dávid Pásztor Aug 30 '17 at 10:21
  • The problem is i have not response for this request, no error, no data, no response.. From iphone 5 with 4g runs. The url is ok, the backend returns the requested data but the app does not receive anything – sergioliip Aug 30 '17 at 10:44
  • This doesn't seem like a programming error, this seems like a network setup issue on your iPhone 7. – Dávid Pásztor Aug 30 '17 at 10:47
  • Thanks Dávid for your help, I have tried with another iphone 7 and runs, the problem was the first iphone 7 have consumed the data – sergioliip Aug 30 '17 at 10:56

0 Answers0