如何花一些时间(60秒)快速重新发送OTP按钮

问题描述 投票:0回答:1

我具有带OTP验证的注册屏幕。。一旦我点击regstrButton,那么OTP就会发送到已注册的手机号码。.那时,如果我点击重新发送otp按钮,则重新发送otp按钮将在60秒后显示60秒的时间。重新发送otp到注册号..如下图所示

enter image description here

重新发送按钮需要显示60秒的时间,之后我需要重新发送otp如何?

enter image description here

我的otp服务代码:

 @IBOutlet weak var otpcountLabel: UILabel!

 func otpService(){

let parameters = ["mobile_number": phoneNumTextField.text as Any,
                  "otp": otpTextField.text as Any]

let url = URL(string: "https://dev..com/webservices/otpverify")
var req =  URLRequest(url: url!)
req.httpMethod = "POST"
req.addValue("application/json", forHTTPHeaderField: "Contet-Type")
req.addValue("application/json", forHTTPHeaderField: "Accept")

guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) else {return}
req.httpBody = httpBody
let session = URLSession.shared

session.dataTask(with: req, completionHandler: {(data, response, error) in
    if response != nil {
        // print(response)
    }
    if let data = data {
        do{
            let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
            print("the json of otppppppppp \(json)")
            let mobileNum = json["mobile_number"] as! [String : Any]

            DispatchQueue.main.async {
                if (self.otpTextField.text == String(self.otpField!)){
                    print("registration successfullllll...")
                    let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
                    self.present(loginVC, animated: true)
                }
                else{
                    print("register fail")
                }
            }
            //}
        }catch{
            print("error")
        }
    }
}).resume()
}

这里otpField包含otp

我的resendotp按钮中的操作

@IBAction func sendOTPButton(_ sender: Any) {

    otpService()
}

@IBAction func resendOTPButton(_ sender: Any) {
    print(" resend otp butn tapped")
}

请帮助我输入代码。

json swift time uibutton otp
1个回答
0
投票
如果您想在60秒后重新发送otp
© www.soinside.com 2019 - 2024. All rights reserved.