I am posting to my server using Alamofire, in my Register VC I have one button with text fields
and when user click the register button here is what happens
@IBAction func RegisterBtn(_ sender: UIButton) {
guard let mobile = Mobilelbl.text?.trimmed, !mobile.isEmpty else {return }
guard let city = CityLbl.text?.trimmed, !city.isEmpty else {return }
//guard let email = EmailLbl.text?.trimmed, !email.isEmpty else {return }
//guard let pass = PassLbl.text, !pass.isEmpty else {return }
guard let name = nameLbl.text, !name.isEmpty else {return }
API.Register(name: name, mobile: mobile, pass: "", city: city, email: "NewApp") { (error: Error?, success: Bool) in
if success {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
self.navigationController!.pushViewController(nextViewController, animated:true)
print("Registerd Successfuly")
}
}
}
API.Register code
class func Register(name: String, mobile: String, pass: String, city: String, email: String, completion: @escaping (_ error: Error?, _ success: Bool)->Void){
let url = URLs.register
let parameters = [
"phone": mobile,
"city": city,
"email": email,
"name": name,
"password": pass ]
AF.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default , headers: nil)
.validate(statusCode: 200..<300)
.responseJSON { response in
switch response.result
{
case .failure(let error):
completion(error, false)
print(error)
case .success(let value):
let json = JSON(value)
if let id = json["data"]["id"].string {
print("id: (id)")
//Save api token to user defaults
Helper.saveApiToken(id: id, mobile: mobile)
completion(nil, true)
}
}
}
}
there is no feedback after success registration or failure, I checked my database I found user registered but in xcode it is not printing any results!
question from:
https://stackoverflow.com/questions/65903623/alamofire-post-giving-no-response 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…