[英]IOS: How to verify user's phone number using codes
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请帮忙
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:所以流程如下:
Unfortunately, there's no way to access text messages received by user from within an app on iOS devices (unlike Android).不幸的是,无法访问用户从 iOS 设备上的应用程序中收到的短信(与 Android 不同)。 The proof link was already provided.已经提供了证明链接。 So the user has to manually enter the verification code from the message.所以用户必须手动输入消息中的验证码。
Ok I tell the information how was I already did my project in before好的,我告诉信息我之前是如何完成我的项目的
Step-1第1步
when user press the Verify Number
button当用户按下Verify Number
按钮时
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);
其次,我以编程方式生成随机数,如NSUInteger r = arc4random_uniform(16);
Step-2第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.将随机数与有效电话号码一起发送到服务器,服务器使用 SMTP 服务器将随机数发送到特定的手机号码。
Step-3步骤 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 the Next Screen
else show the Alert
.在你的手上你有随机数,所以打开UIAlertview
为用户输入有效的随机数,如果用户输入了有效的数字,则显示Next Screen
否则显示Alert
。
To verify any mobile number you can use third party api's which are available for mobile as well as backend server.要验证任何手机号码,您可以使用可用于移动设备和后端服务器的第三方 API。 You can use Twilio Messaging Api .您可以使用Twilio Messaging Api 。 To use this API follow below steps:要使用此 API,请按照以下步骤操作:
Also, there is another api which you can directly integrate into your mobile application.此外,还有另一个 api,您可以直接将其集成到您的移动应用程序中。 You can find this Sinch Api here.你可以在这里找到这个Sinch Api 。
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.但是,在 iOS 4 之后,获取设备的电话号码是非常不可能的。 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.即使您确实使用一些我不确定完全有效的私有 api 获取设备编号,Apple 也很有可能拒绝您的应用程序。
Refer to the following stack overflow discussion- Programmatically get own phone number in iOS参考下面的堆栈溢出讨论—— 在 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.您可以生成一个代码并将其发送到用户指定的号码,然后输入该代码以验证用户是否拥有该设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.