Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

ios - Alamofire post giving no response

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...