Login to Swift Authorization

Asked

Viewed 84 times

0

I’m consuming data of a certain API for login, she returns the Token of correct access, and otherwise returns the ERROR, but I cannot 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()


}
  • Junior, I don’t understand what you mean by "I can’t move to another screen...". At what point would you like to make this transition?

1 answer

0

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

In this case you can present 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)
}
  • Remembering that you have to see if this present/push call is being called in the Main Thread

Browser other questions tagged

You are not signed in. Login or sign up in order to post.