iOS simple implementation of SMS verification function

1. Register the application to obtain the appKey and appSecret

( 1 ) Go to the Mob official website to register as a Mob developer;

( 2 ) Go to the application management background to create a new application.

For detailed registration steps, please click this  document  description

2. Integrate SMSSDK

( 1 ) cocoapods integration method

To install via CocoaPods , just add in the Podfile :

under 'mob_smssdk'

After adding, execute the pod install / pod update command.

( 2 ) Manual integration method

1. Get SMSSDK:

Click on the link to download the latest version of the SDK . After decompression, you will get the following file structure:

2. Import SDK:

Drag the folder marked by the red box in the figure below (including MOBFoundation.framework and SMS_SDK.framework ) into the project


Confirm the check and click finish to complete the import


3. Add dependency library :

List of dependencies required by the SDK :

need:

libz.dylib

libicucore.dylib

MessageUI.framework

JavaScriptCore.framework

libstdc++.dylib

Note: If you run an error on XCode7 , you need to add these dependent libraries

SystemConfiguration.framework

CoreTelephony.framework

AdSupport.framework

Optional:

AddressBook.framework (required for address book function)

AddressBookUI.framework (required for address book function)


3. Configure appkey and appSecret

Add a key-value pair to the info.plist file in the project, the keys are  MOBAppKey  and  MOBAppSecret  , and the values ​​are appkey and appSecret applied for in step 1

The private key required to configure the address book friend function , the key is: NSContactsUsageDescription


4. Use sdk to send and verify verification codes

import header file

#import <SMS_SDK/SMSSDK.h>

Request SMS verification code

//with custom template
  [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:@"13800138000" zone:@"86" template:@"123456" result:^(NSError *error) {
 
        if (!error)
        {
            // request succeeded
        }
        else
        {
            // error
        }
    }];
//without custom template
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:@"13800138000" zone:@"86"  result:^(NSError *error) {
 
        if (!error)
        {
            // request succeeded
        }
        else
        {
            // error
        }
    }];

Note that the template id is added in the SMS template under the SMSSDK product in the background of the official website (you need to apply for an application with a custom SMS signature to add a SMS template)


Submit SMS verification code

Objective-C

[SMSSDK commitVerificationCode:@"1234" phoneNumber:@"13800138000" zone:@"86" result:^(NSError *error) {
 
        if (!error)
        {
            // verify successful
        }
        else
        {
            // error
        }
    }];






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325442953&siteId=291194637