I have alertview with textfield for otp validation,but if OTP is mismatched then another alertView will show message "OTP not matched", and on click ok button then previous alertview (alertview with OTP textfield) will appeared again to enter OTP.
@IBAction func btnRegisterTapped(_ sender: UIButton) {
if !Validate(){
return
}
// get otp session
APIController.registerUser(Email: self.txtfldEmail.text!, Nonce: self.registerNonce) { (data1) in
print("data1 :=> \(data1)")
let alertController = UIAlertController(title: "BrainCal", message: "Please verify your OTP for login", preferredStyle: .alert)
let OkAction = UIAlertAction(title: "OK", style: .default, handler: {
alert -> Void in
APIController.registerUserWithOtp(Email: self.txtfldEmail.text!, Password: "", Nonce: self.registerNonce, Otp: (alertController.textFields?.first?.text!)!, Otp_Session: "\(data1["otp_session"]!)", SuccessHandler: { (response) in
print(response)
let dict = response as NSDictionary
if UserDefaults.standard.value(forKey: "LoginUserData") != nil{
UserDefaults.standard.removeObject(forKey: "LoginUserData")
}
UserDefaults.standard.set(NSKeyedArchiver.archivedData(withRootObject: dict), forKey: "LoginUserData")
self.performSegue(withIdentifier: "MainSegue", sender: self)
})
})
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter Otp Here"
textField.keyboardType = .numberPad
NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextFieldTextDidChange, object: textField, queue: OperationQueue.main) { (notification) in
OkAction.isEnabled = textField.text!.characters.count > 0
}
}
OkAction.isEnabled = false
alertController.addAction(OkAction)
self.present(alertController, animated: true, completion: nil)
}
}