2016-04-09 36 views
1

我爲我的應用程序構建了一個註冊表單,我需要通過短信向用戶發送驗證碼以完成註冊過程。如何在swift中通過短信發送驗證碼2

我試圖使用MFMessageComposeViewController,但它打開設備上的對話短信,使用戶可以看到代碼。

我也檢查了發送短信的第三方網絡,但是國家代碼存在問題。我知道它可能會使用whatsapp來確認用戶。

它是正確的做法嗎?

這是我嘗試過的話題: Sending SMS in iOS with Swift

+2

你應該在你的後端做這件事。 iOS應用程序向後端提交請求。後端生成一個隨機代碼。後端向用戶發送短信。用戶輸入代碼。 iOS應用提交回後端進行驗證。您可以使用Twilio等服務發送短信(https://www.twilio.com/)。 – markwatsonatx

回答

0

我會給數字一試!它是Twitter Fabric包的一部分,使用起來非常簡單。用戶輸入他們的電話號碼,Fabric負責驗證號碼。

2

實現此目的的最佳方法是創建一些視圖,以允許用戶輸入具有國家代碼的電話號碼,服務器可以使用該國家代碼發送啓動O​​TP驗證的請求。要達到此目的,您需要:

  1. 創建視圖控制器。
  2. 將電話號碼和國家代碼上傳到服務器。
  3. 通過驗證OTP驗證請求。

正如丹所提到的,你可以在Fabric使用Digits爲宗旨,爲一個偉大的UX創建自定義視圖。

另一方面,您也可以使用MSG91中名爲SendOTP的服務 - 您可以將它用於內部測試和開發想法,因爲它們可爲您提供5,000個免費的OTP SMS。該服務具有一套完整的API,您可以在後臺以及應用程序前端實施這些API。此外,他們提供了一個framework,以便您不需要創建視圖,但只需要presentViewController和調用delegate方法來了解驗證過程中發生了什麼 - 例如CancelledVerifiedFailed

迅速執行相同的看起來像這樣的:

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

聲明:我在沒有辦法,贊成上述服務 - 你可以自由選擇任何你喜歡的。

謝謝!

+0

很好的答案。 TNX人:) –

+0

@NirTzin upvote和/或接受,如果你喜歡:) ..高興地幫助! - Fennec。 – Fennec