简体   繁体   English

IOS:如何使用代码验证用户的电话号码

[英]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:所以流程如下:

  1. User enters their phone number in the app and presses the "Verify Number" button.用户在应用程序中输入他们的电话号码并按下“验证号码”按钮。
  2. 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".在应用程序中,您还会显示一个文本字段供用户输入生成的代码和一个新按钮,如“检查代码”。
  3. 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.后端生成一个新代码(只是一个随机代码),将其存储到数据库(如 ID、PhoneNumber、GeneratedCode、DateOfGeneration)并将带有代码的文本消息发送到指定的电话号码。
  4. When the user receives the message he or she enters the code to the checking input field and presses the "Check" button.当用户收到消息时,他或她将代码输入到检查输入字段并按下“检查”按钮。
  5. The mobile app sends another request to the backend with the phone number entered earlier and the code entered by the user now.移动应用程序使用之前输入的电话号码和用户现在输入的代码向后端发送另一个请求。
  6. 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).不幸的是,无法访问用户从 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,请按照以下步骤操作:

  1. Register account on Twilio and get key from account.在 Twilio 上注册帐户并从帐户中获取密钥。
  2. Get user's phone number from mobile application.从移动应用程序获取用户的电话号码。
  3. When user click on the "Verify Number" button, call web-service with the number.当用户单击“验证号码”按钮时,使用该号码调用网络服务。
  4. 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.当您调用 Web 服务时,编写一个逻辑来使用 Twilio 消息传递 api 发送随机数以向用户发送消息。
  5. 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.此外,还有另一个 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.

相关问题 iOS如何查找用户电话号码的国家代码? - iOS how to find country code of the user's phone number? 如何在iOS中实时格式化电话号码(使用UITextfield时)以获取不同的区域代码? - How to format phone number realtime (when using UITextfield) in iOS for different region codes? IOS如何验证输入的电话号码实际上是用户电话号码? - Ios how can I verify that the phone number entered is actually the users phone number? 如何获取用户的电话号码? - How to get user's phone number? 如何在 flutter 中获取用户的电话号码 - how to get user's phone number in flutter 如何使用Firebase在iOS上验证用户的电子邮件地址? - How to verify a user's email address on iOS with Firebase? 如何在Swift中使用Cognito用户池注册用户并验证其电话号码? - How to sign up a user and verify their phone number with Cognito User Pools in Swift? 如何使用loginViewFetchedUserInfo获取用户电话号码? - how to fetch user phone number using loginViewFetchedUserInfo? 如何在iOS设备中获取用户来电电话号码 - How to get user incoming call phone number in iOS device 如何在不使用第三方服务的情况下检查用户的电话号码 - How to check a user's phone number without using third-party services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM