Skip to content

Instantly share code, notes, and snippets.

@oguzhanvarsak
Last active January 21, 2022 12:40
Show Gist options
  • Save oguzhanvarsak/984e71758948960b9af7a0b6a9e74279 to your computer and use it in GitHub Desktop.
Save oguzhanvarsak/984e71758948960b9af7a0b6a9e74279 to your computer and use it in GitHub Desktop.
Alert View contains Security Text Field that auto detects verification code from Messages.
/* The verification code SMS must follow this model:
* "Your verification code: XXXXXX"
* You can localize it
* "Doğrulama kodunuz: 123456"
* but the important part is;
* the ":" character and the code must position at the end.
* Otherwise the textfield won't recognize it.
*/
let ac = UIAlertController(title: "Verification Code", message: "Enter the code.", preferredStyle: .alert)
ac.addTextField { (securityCodeTextField : UITextField!) -> Void in
securityCodeTextField.textContentType = .oneTimeCode
}
let submitAction = UIAlertAction(title: "Done", style: .default) { [unowned ac] _ in
let answer = ac.textFields![0].text
// Do anything with the verification code
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.destructive, handler: nil)
ac.addAction(submitAction)
ac.addAction(cancelAction)
self.present(ac, animated: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment