i am working on an app in which i take a field of mobile number of user after entering mobile number there is a option for verify phone number.
but i don't know the functionality of how to verify a user's phone number within the app using codes.I search for similar type of questions but didn't get the exact solutions.
i am sending a screenshot of my app where i want to put that functionality.
i didn't apply any codes for this
please help

- 2,142
- 1
- 18
- 39
-
@Anbu.Karthik No this is not a duplicate of that question. He wants to verify phone numbers linked to an account. Like facebook or whatsapp do – NSNoob Oct 30 '15 at 06:30
-
@Anbu.Karthik i want answer and i check that question but didn't get any solution thats why i ask. if you are unable to give answers please stop giving flags to the question because due to these duplication flags many of us are failed to find exact solution of problems – Abhinandan Pratap Oct 30 '15 at 06:31
-
do u need the answer like , if user press verify the Number button, you can send the some OTP for user and user manually enter the vaild code after that continue the process correct – Anbu.Karthik Oct 30 '15 at 06:34
-
@iABP It really depends on your architecture really. Some companies invest in building their own Telecom networks to use two-step authentication. some like whatsapp and others user external APIs like Plivo etc. – NSNoob Oct 30 '15 at 06:38
-
1The basic working is, your device sends a request to your server or your API. That remote end then sends a verification code to your mobile phone. If your app is running on that device, it parses text from that sms, sends it to remote server and sets the account as verified. It then automatically deletes the sms. If your app is not running on that device, you can see the code from sms and enter it manually – NSNoob Oct 30 '15 at 06:40
-
@Anbu.Karthik yes i want similar functionality of OTP – Abhinandan Pratap Oct 30 '15 at 06:40
-
I am not going to post it as an answer because it is a vague answer but to be fair you asked a vague question. Lets hope someone else can provide you with a thorough and exclusive answer. – NSNoob Oct 30 '15 at 06:41
-
@NSNoob how do you say that this question is vague. i explained everything here as par the requirements – Abhinandan Pratap Nov 02 '15 at 08:50
-
@iABP I said it is vague because you did not provide any information about the infrastructure you are using, your architecture, your desired approach etc. I did my best however to set you on the right path. Hope it was helpful. – NSNoob Nov 02 '15 at 08:58
4 Answers
You need a backend that can generate and save codes for each phone number and also send a text message with those codes. So the flow is as follows:
- User enters their phone number in the app and presses the "Verify Number" button.
- You send a request to your backend with the number provided. In the app, you also displays a text field for user to enter the generated code and a new button like "Check code".
- The backend generates a new code (just a random one), stores it to the database (like ID,PhoneNumber,GeneratedCode,DateOfGeneration) and sends a text message with the code to the phone number specified.
- When the user receives the message he or she enters the code to the checking input field and presses the "Check" button.
- The mobile app sends another request to the backend with the phone number entered earlier and the code entered by the user now.
- The backend looks to the database for the "Phone number" - "Code" pair and responds with failure (the code is incorrect, try again) or success (the phone is verified).
Unfortunately, there's no way to access text messages received by user from within an app on iOS devices (unlike Android). The proof link was already provided. So the user has to manually enter the verification code from the message.

- 479
- 6
- 18
Ok I tell the information how was I already did my project in before
Step-1
when user press the Verify Number
button
initially I check the phone number is valid or not(means phone number count/length).
second I generate the random number on progrmatically like
NSUInteger r = arc4random_uniform(16);
Step-2
send the random number to server along with the vaild phone number , the server send the random number to the particular mobile number using SMTP Server.
Step-3
in your hand you have the random number , so open the
UIAlertview
for user type the valid random number , if user typed the vaild number show theNext Screen
else show theAlert
.

- 82,064
- 23
- 174
- 143
To verify any mobile number you can use third party api's which are available for mobile as well as backend server. You can use Twilio Messaging Api. To use this API follow below steps:
- Register account on Twilio and get key from account.
- Get user's phone number from mobile application.
- When user click on the "Verify Number" button, call web-service with the number.
- When you'll call the web-service, write a logic to send the random number with the Twilio messaging api to send message to user.
- When user get this number through SMS, You can tell user to enter the number and verify it.
Also, there is another api which you can directly integrate into your mobile application. You can find this Sinch Api here.

- 1,272
- 1
- 12
- 25
To verify against your device's phone number, first, you need to get the phone number from your device and then you can compare against. However, after iOS 4, getting phone number of your device is quite impossible. Even if, you do get the device's number using some private api which I am not sure works entirely, there is a huge possibility for Apple to reject your app.
Refer to the following stack overflow discussion- Programmatically get own phone number in iOS
Just a suggestion: You probably want to look for a work around based on your business goal. For example, rather than checking for device's phone number directly. You can generate a code and send that to the number specified by the user and then enter that code to verify that the user has that device.