Login to Swift Authorization

0

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


}
    
asked by anonymous 18.09.2017 / 18:10

1 answer

0

As I understand it, you want to direct the user to another screen if the login is successful.

In this case you can display the next screen as a modal:

if loginOK {
    present(yourNextViewController, animated: true)
}

Or add it to the top of your navigationController :

if loginOK {
    navigationController?.pushViewController(yourNextViewController, animated: true)
}
    
21.03.2018 / 18:08