xcode - Alamofire http post - Registering user Swift 3 -


quick question: i'm registering user database using alamofire library. got endpoint , parameters backend developer , tested in postman myself , data passing fine. i'm implementing in register view controller been getting no response. here implementation. fyi: left user type off view controller. end user not supposed know user type 3. may doing wrong here. i'm not getting no response in output.

let params = ["username":usernamefield.text!,                   "firstname":firstnamefield.text!,                   "lastname":lastnamefield.text!,                   "password":passwordfield.text!,                   "usertype":"3",                   "email":emailaddressfield.text!     ]      let apimethod = "http://api.example.com"      alamofire.request(apimethod, method: .post, parameters: params, encoding: urlencoding.default).responsestring { (response) in          print(response);          let alertcontroller = uialertcontroller(title: "registration successful!", message: nil, preferredstyle: .alert);          alertcontroller.addaction(uialertaction(title: "ok", style: .default,handler: nil));          self.present(alertcontroller, animated: true, completion: nil)      }    }         if let json = response.result.value as? dictionary<string, string> {            print ("json: \(json)")            if (json["register_status"]! == "userexist") {                 return         } else {                 self.performsegue(withidentifier: "registersuccess", sender: self)            }           } 

once user has registered properly, response should be:

{   "username": "userregister",   "register_status": "registrationcomplete",   "register_date": "11/10/2016" } 

but if user exists message:

{   "username": "userregister",   "register_status": "userexist",   "register_date": "11/10/2016" } 

what doing wrong in swift 3 code?

edit (adding register view controller) clarity: register view controller above swift code

i if response json. debug code. also, suggest put breakpoints , check response in console.

alamofire.request(apimethod, method: .post, parameters: params, encoding: urlencoding.default).responsejson {response in     var err:error?     switch response.result {     case .success(let json):          print(json)           // update ui on main thread          dispatchqueue.main.async {                 let alertcontroller = uialertcontroller(title: "registration successful!", message: nil, preferredstyle: .alert);                  alertcontroller.addaction(uialertaction(title: "ok", style: .default,handler: nil));                  self.present(alertcontroller, animated: true, completion: nil)         }      case .failure(let error):          err = error          print(err)     } } 

if doesn't you, please share rest client request payload can further.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -