如何通过短信发送validation码2

我为我的应用程序构build一个registry单,我需要通过短信向用户发送一个validation代码,以完成注册过程。

我试图使用MFMessageComposeViewController,但它打开设备上的对话短信,使用户可以看到代码。

我也检查了网站的第三方发送短信,但国家代码有问题。 我知道它可能会使用whatsapp来确认用户。

什么是正确的做法呢?

这是我试过的主题: 用Swift在iOS中发送短信

实现这一点的最好方法是创build一些视图,允许用户input具有国家代码的电话号码,服务器可以使用该国家代码发送启动O​​TPvalidation的请求。 要做到这一点,你需要:

  1. 创build视图控制器。
  2. 将电话号码和国家代码上传到服务器。
  3. 通过validationOTPvalidation请求。

正如Dan所提到的那样,您可以将Fabric中的 Digits用于此目的,并为一个伟大的UX创build自定义视图。

另一方面,您也可以使用MSG91中称为SendOTP的服务 – 您可以将其用于内部testing和开发想法,因为它们提供了5,000免费的OTP SMS。 该服务具有一套完整的API,您可以在应用程序的前端执行后端应用程序。 此外,他们提供了一个框架,以便您不需要创build视图,而只需要presentViewController并调用delegate方法来了解validation过程中发生的事件(例如“ Cancelled或“ Verified或“ Failed

Swift的实现如下所示:

  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") } } 

免责声明:我绝不认可上面提到的服务 – 你可以自由select你喜欢的任何东西。

谢谢!

我会给数字一个尝试! 它是Twitter Fabric包的一部分,使用起来非常简单。 用户input他们的电话号码,Fabric负责validation号码。