これを達成する最善の方法は、サーバーがOTP検証を開始するための要求を送信するために使用できる国番号でユーザーが電話番号を入力できるようにするためのビューを作成することです。これを実現するには、以下を行う必要があります。
- View Controllerの作成。
- 電話番号と国コードをサーバーにアップロードします。
- OTPを確認して要求を検証します。
Danによって言及されたように、FabricにDigitsを使用して、偉大なUXのカスタムビューを作成することができます。
一方、MSG91のSendOTPというサービスを使用することもできます。無料のOTP SMSを提供するため、内部テストと開発のアイデアに使用できます。サービスには、バックエンドでもアプリのフロントにも実装できるAPIの完全なセットがあります。また、Cancelled
またはVerified
またはFailed
など、確認処理中に何が起きたかを知るために、を提供して、ビューを作成する必要はなく、presentViewController
とdelegate
メソッドのみを呼び出します。このように同じルックスの
スウィフト実装:
class OTPFrame: UIViewController, sendOTPAuthenticationViewControllerDelegate {
func loadOTPFramework() {
SendOTP.sharedManager().startWithApiId("yourAppID")
let frameworkPath: NSString = NSBundle.mainBundle().privateFrameworksPath!
let frameworkBundlePath: NSString = frameworkPath.stringByAppendingPathComponent("SendOTPFramework.framework")
let frameworkBundle : NSBundle
= NSBundle(path: frameworkBundlePath as String)!
let authenticationViewController: AuthenticationViewController = AuthenticationViewController(nibName: "AuthenticationViewController", bundle: frameworkBundle)
authenticationViewController.delegate = self self.presentViewController(authenticationViewController, animated: true, completion: nil)
}
func authenticationisSuccessfulForMobileNumber(mobNo: String!, withCountryCode countryCode: String!) {
print("Success")
}
func canceledAuthentication() {
print("Cancelled")
}
func authenticationisFailedForMobileNumber(mobNo: String!, withCountryCode countryCode: String!) {
print("Failed")
}
}
免責事項:私は、決して、上記のサービスを推奨するもの - あなたが好きな自由に選択できます。
ありがとうございました!
あなたはおそらくバックエンドでこれを行うべきです。 iOSアプリからバックエンドにリクエストが送信されます。バックエンドはランダムなコードを生成します。バックエンドはSMSをユーザーに送信します。ユーザーがコードを入力します。 iOSアプリからバックエンドに戻って確認します。 Twilioのようなサービスを使ってSMSメッセージ(https://www.twilio.com/)を送ることができます。 – markwatsonatx