Categories
Development Swift

How to give count down for OTP in Swift

I need to give 60 sec time countdown for resend otp. and if i click verifyOtp butn then count down to be stop. and i want that otp to be expaire. in count down time resend otpbutton to be disable.. please suggest me how to set count down for resendotp.

i am getting otp in registrService().

    do{
                var json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
                let regUserStatus = json["status"] as? String

                if regUserStatus == "sucess"
                {
                    print("the json regggggggggggis \(json)")
                    let phNum = json["mobile_number"] as? Int
                    let status = json["status"] as? String
                    self.otpField = json["otp"] as? Int
                }
                else{
                    DispatchQueue.main.async {
                        self.registerButton.isHidden = false
                        self.sendOtpButton.isHidden = true
                        self.otpTextField.isHidden = true
                        self.resendButn.isHidden = true
                        self.otpcountLabel.isHidden = true
                        AlertFun.ShowAlert(title: "", message: "user exist", in: self)
                    }

                }
            }

resendButton .

   @IBAction func resendOtpButn(_ sender: Any) {
    print("resendotp tapped")

    registerService()
   }

Leave a Reply

Your email address will not be published. Required fields are marked *