3

i build a register form for my app and i need to send the user a verifiation code by sms in order to complete the registration proccess.

i tried to use MFMessageComposeViewController but its open the dialog sms on the device so the user can see the code.

i also checked the web for 3party of sending sms but there is a problem with the country code. i know its posible becuse whatsapp do it to confirm the user.

what it the right way to do it?

this is the topic the i tried: Sending SMS in iOS with Swift

Community
  • 1
  • 1
Nir Tzin
  • 45
  • 1
  • 6
  • 4
    You should probably do this on your backend. iOS app submits a request to the backend. Backend generates a random code. Backend sends SMS to user. User enters in code. iOS app submits back to backend to verify. You can use a service like Twilio to send SMS messages (https://www.twilio.com/). – markwatsonatx Apr 09 '16 at 14:42

2 Answers2

3

The best way to achieve this is by creating some views for allowing the user to enter the phone number with the country code which can be used by a server to send a request for initiating the OTP verification. To achieve this you need to:

  1. Create View Controllers.
  2. Upload Phone Number and Country code to the server.
  3. Validate the requests by verifying the OTP.

As mentioned by Dan, you can use Digits in Fabric for that purpose, and create custom views for a great UX.

On the other hand, you can also use a service called as SendOTP from MSG91 - you can use it for internal testing and development ideas as they provide you with 5,000 free OTP SMS. The service has a complete set of APIs which you can implement on the backend as well on the app front. Also, they provide a framework so that you don't need to create the views, but only presentViewController and call delegate methods for knowing what happened during the verification process - such as Cancelled or Verified or Failed.

Swift implementation of the same looks like this:

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

Disclaimer: I, in no way, endorse the services mentioned above - you are free to choose whatever you like.

Thank You!

tush4r
  • 867
  • 12
  • 21
  • @NirTzin upvote and/or accept if you like :) .. Happy to help! - Fennec. – tush4r Apr 11 '16 at 10:12
  • Try putting the checks at the crash point or try to look at the issues on their github repo. – tush4r Jul 04 '18 at 15:08
  • Hi @Fennec! Both of the above services you mentioned aren't available, as I checked. It'd be great if you could mention some alternatives I could use. Thanks! – N a y y a r Dec 18 '19 at 18:04
1

I would give digits a try! It's part of the Twitter Fabric package and it's very simple to use. The user enters their phone number and Fabric takes care of validating the number.

Dan Levy
  • 3,931
  • 4
  • 28
  • 48