Registration via post swift

0

I am sending user registration, it is the first time I use swift, I have my API for registration which takes the following parameters via POST:

name
lastname
email
password
mobile

I send the information as follows:

if(user == "" || lname == "" || email == "" || phone == "" || pass == ""){
        //Mensaje de advertencia
        self.showDialog(tit: "AVISO", msj: "Ingresa todos los datos para poder continuar con tu registro")
    } else {
        //Enviamos informacion de registro
        var url = "http://website.com/api/users/registrer"
                // POST data =  name, lastname, email, password, mobile
        var params: Parameters = ["name":textUsuario.text,"lastname":textLastName.text,"email":textEmail.text,"password":textPassword.text,"mobile":textPhone.text]

        request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: nil)
            .responseJSON(completionHandler: { (result) in
                switch(result.result){
                case .success(let value):
                    self.showDialog(tit: "Success", msj: "Se ha registrado correctamente")
                case .failure(let error):
                    self.showDialog(tit: "Failure", msj: "Se ha producido un error, vuelva a intentarlo")
                }
            })
    }

Testing via POSTMAN gives me the following information my API when registering a user:

{
    "status": 200,
    "message": "Registrado correctamente"
}

The question here is how can I control that, since it always sends me case .failure(let error): in swift.

    
asked by DoubleM 21.03.2018 в 01:53
source

0 answers