Open up your workspace and go to
main.storyboard file. Then open up assistant view so also see
ViewController.swift:

Add a textfield and add an outlet called phoneNumber. Set the
keyboard type of the field to phone number

Add an SMS verification button and create an action called
smsVerification

Add a callout verification button and create an action called
calloutVerification

Add a label and call an outlet called status

Add an activity indicator and an outlet called spinner, and then
check the box to hide when no animated

Embed the ViewController in a navigation controller editor

Add your constraints and the first screen is done. The next thing we are
going to do is to add some code to do a callout verification. I want to
start with this because the callout verification does not require any
additional screens.

##Callout Verification The verification flow for a callout is pretty
neat. Just imitate a callout verification and when the callback comes to
the client you are actually done.

How does it work? Sinch will place a call to the given phone number and
when the user picks up we prompt the user to press 1. If they do it’s a
success, but if they don’t then it is treated as a fail (or if they
don’t pick up etc).

Open up ViewController.swift and add an import for
SinchVerification:

importSinchVerification;

At the top of your class, add two variables to hold the verification and
one to hold the application key.

varverification:Verification!;varapplicationKey="your key";

Great! Now we want to start a callout verification once the user clicks
on the callout verification button.

As you can see that’s not a lot of code to make this roll. You might
have noticed that I have a disbleUI(Bool) call in there, and that’s
a small method to disable the UI while waiting for the call. This is
important to do because if the user starts multiple verification
requests they might get stuck in a loop where they never get verified
and the phone just keeps ringing. I implemented a timeout for 30 seconds
before I consider it to be a fail and the user can try again.

Another way of adding verification is the
classic SMS PIN method, which I’m sure you have used. The downside of
SMS, in my opinion, is that you need the user to enter a code which does
add some friction to the user experience.

To accomplish an SMS verification, you will need a new view where a user
can enter a code. Add a new ViewController to the solution and call in
EnterCodeViewController.swift.

Open up Main.Storyboard and add a view controller to the board and
set the first responder to the newly created Controller

Add a textfield and an outlet called code

Add a button and an action called verify

Add label and an outlet called status

Lastly a spinner and an outlet called spinner

Add a segue from ViewController.swift to
EnterCodeViewController.swift and call it enterPin.

Add your constraints and make it look how you want, but it should look
something like this:

Initiating an SMS verification is very similar to Callout. The big
difference here is when you get the success callback, it doesn’t mean
its verified, it just means that we have sent an SMS. What we need to do
after that is to send in a code that we get from user input to verify
the code. In this case we do that in a separate view controller. So once
we have the success, we perform the segue to show the entertain
controller.

You now have a verified number for your user. With this implementation
you only know on the client side that the number is verified. In a real
world app, you would need to tell your backend that the number is
verified. You could accomplish that in two ways. Either calling that
update on the success flow from the client. Or your own callbacks that
we have for verification (recommended).