iOS Development--app integrated SMS Verification Code

Source: Internet
Author: User

Whether on the Web page or on the client, whenever we register, often will be SMS or email verification, this is a good security mechanism. For the user experience, if it is on the PC Web page, the mailbox or SMS verification is more convenient, if it is on the phone, then the use of SMS verification is more convenient. In this blog we will implement the SMS verification code in the iOS app. Example demo I have integrated into https://github.com/chenyufeng1991/iOS-Oncenote.

Here I will use the mob's SMS Verification Code SDK to develop. The official website address is: Http://www.mob.com/#/index. Mob social sharing and SMS Verification Code SDK do well, you can try to develop. In our commissioning process, we need to note that we can only send 5 verification text messages (within 12 hours) to the same number. If you exceed this limit, you will not receive a verification message. This is a safe way for telecom operators to identify and prevent spam messages. Imagine if you constantly send a verification code to a number, will it become a spam message? So there will be this quantity limit. Also because of this limitation, let us debug the program to increase the difficulty, also means that basically in a day we can only run 5 times the program .... Do you have to think about it every time you debug a program? And for this reason, this simple function I tested for 2 days ... Who gave me only one number?

The specific implementation steps are as follows:

(1) Log in to mob Mobile developer Service platform, sign in, then download the SMS Verification Code sdk,sms for IOS and drag it directly into the project. There is also a sample demo, do very good, support the global send.

(2) Enter the background to create an application. Get app key and app secret, which you'll use in your project. So that we have the service side.



(3) Send the verification code. Just send the country code + mobile number to the server, you can. You can usually receive a verification code within 5 seconds. China's national code is 86. If your app needs to be published abroad, it needs to be configured accordingly. The country's choice was made in the demo that comes with it.

            [Smssdk getverificationcodebymethod:smsgetcodemethodsms phonenumber:@ "18888888888"                                     zone:@                         " Customidentifier:nil                                   result:^ (nserror *error) {                                     if (!error) {                                       //Send verification code successful callback;                                     }                                     else{                                       // A callback that fails to send the verification code; If you enter the wrong phone number or any number, it will be recalled;}                                   ];


(4) Verify that the verification code is correct. As soon as you send the phone number and the verification code that you just received to the server, the server side will perform the matching verification and then make the appropriate callback.

Note: 1). A verification code can only be verified once, once the first verification fails, even if the second time to enter the correct verification code, will not verify success.

2). After receiving the verification code, only valid within 60s, more than 60s, even if the code is correct, it will verify the failure.

The implementation code is as follows:

[Smssdk commitverificationcode:1234 (Verification code) phonenumber:18888888888 zone:@ "" "result:^ (Nserror *error) {    if (!error) {      //callback after successful validation;    }//if ();    else{      //callback after verification failure;    }  ];

Summary: The verification code can be used to register or retrieve the password of the two parts, the purpose is to verify your identity. How to extend this verification code function, it depends on your idea.


iOS Development--app integrated SMS Verification Code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.