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()
}