現在申請或註冊任何服務,非常多都需要透過收發簡訊驗證碼,來確認是否為真實的使用者!過去一直都能在Android收到驗證碼後自動填入畫面欄位,而iOS終於在WWDC 2018開始支援呀XD~它建造一個叫做一次性驗證碼欄位 (One Time Code Textfield)。
OneTimeCode型別只能在iOS 12以後版本使用,同事問我要做哪些動作,才能收簡訊驗證碼?其實非常簡單,如下設定即可!
UITextContentType const UITextContentTypeOneTimeCode NS_AVAILABLE_IOS(12_0);
myTextField.textContentType = UITextContentTypeOneTimeCode;
話說Apple自己家做的App,早在iOS 11就支援收發驗證碼,直接填入它們家的App畫面,總是要吊一下蘋果粉的胃口呀XD~
簡訊內容規則,系統會自動判定,剛試過中文「認證碼」、韓語「확인 코드」都能抓到code😌。開發時可以嘗試各式各樣的文字組合喔!
我們目前的需求是六個數字的驗證碼,可以建立六個TextField,focus在其中一個,抓到code後點擊虛擬鍵盤上的code,將一一填入六個TextField。
目前測試過,只能數字開頭+數字結尾,中間穿插英文可行。
- These following verification code CAN be recognized by the system:
A pure number of lengths of 3-8
like : 123 1234 12345 666666 1234567 12345678 …
- These following verification code CANNOT be recognized by the system:
(i).length of code is less than 3 or more than 8 (ii).include letters
like : 1 12 123a 9h7d 123456789 …
- Others:
Security Code AutoFill will only works with System Keyboard. It will not work with custom keyboard.
有兩支手機登入不同Apple帳號,就能使用iMessage無線免費測試囉~
參考:iOS 12 SMS Reading API?、Automatic OTP verification in iOS?、。
隨意留個言吧:)~