I'm consuming data from a certain API to login, it returns me the% correct access%, and if instead returns ERROR , but I can not do move to another screen if the fields are filled correctly, follow the API code below:
let postString = "usuario=" + user + "&senha=" + _psw
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
print("error=\(String(describing: error))")
self.alert(title: "Ops!", msg: "Login inválido.")
return
}
// let httpStatus = response as? HTTPURLResponse
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
print("statusCode should be 200, but is \(httpStatus.statusCode)")
}
let responseString = String(data: data, encoding: .utf8)
print("responseString = \(String(describing: responseString))")
}
task.resume()
}