我具有带OTP验证的注册屏幕。。一旦我点击regstrButton,那么OTP就会发送到已注册的手机号码。.那时,如果我点击重新发送otp按钮,则重新发送otp按钮将在60秒后显示60秒的时间。重新发送otp到注册号..如下图所示
重新发送按钮需要显示60秒的时间,之后我需要重新发送otp如何?
我的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")
}
请帮助我输入代码。