Logo Site EngageLab Mark Colored TransparentDocument
Search

iOS SDK Integration Guide

Overview

The MTVerify iOS SDK is a mobile number authentication SDK that provides fast, secure, carrier-grade phone number verification.

Key Features

  • SDK initialization: Automatically fetch configuration and initialize via AppKey
  • Coverage check: Check whether the current network environment supports the authentication service
  • Number authentication: Initiate mobile number authentication and obtain an authentication token

System Requirements

  • iOS 12.0+
  • Xcode 14.0+

Integration Guide

Manual Integration

  1. Drag MTVerify.xcframework into your project
  2. In Target -> General -> Frameworks, Libraries, and Embedded Content:
    • MTVerify.xcframework: set to Do Not Embed

Quick Start

Swift Example

import MTVerify // 1. Enable debug mode (optional, recommended during development) MTVerifySDK.setDebug(true) // 2. Initialize the SDK MTVerifySDK.setup(appKey: "your_app_key", environment: .production) { result in if result.isSuccess { print("SDK initialization succeeded") } else { print("SDK initialization failed: \(result.message)") } } // 3. Check coverage MTVerifySDK.checkCoverage(phoneNumber: "6281234567890") { result in if result.isSuccess && result.isAvailable { print("Authentication service available, carrier: \(result.operatorCode ?? "")") } } // 4. Initiate authentication MTVerifySDK.startAuthentication(phoneNumber: "6281234567890") { result in if result.isSuccess { print("Authentication succeeded, Token: \(result.token ?? "")") } }
              
              import MTVerify

// 1. Enable debug mode (optional, recommended during development)
MTVerifySDK.setDebug(true)

// 2. Initialize the SDK
MTVerifySDK.setup(appKey: "your_app_key", environment: .production) { result in
    if result.isSuccess {
        print("SDK initialization succeeded")
    } else {
        print("SDK initialization failed: \(result.message)")
    }
}

// 3. Check coverage
MTVerifySDK.checkCoverage(phoneNumber: "6281234567890") { result in
    if result.isSuccess && result.isAvailable {
        print("Authentication service available, carrier: \(result.operatorCode ?? "")")
    }
}

// 4. Initiate authentication
MTVerifySDK.startAuthentication(phoneNumber: "6281234567890") { result in
    if result.isSuccess {
        print("Authentication succeeded, Token: \(result.token ?? "")")
    }
}

            
This code block in the floating window

Objective-C Example

@import MTVerify; // 1. Enable debug mode (optional) [MTVerifySDK setDebug:YES]; // 2. Initialize the SDK [MTVerifySDK setupWithAppKey:@"your_app_key" environment:MTEnvironmentProduction completion:^(MTSetupResult *result) { if (result.isSuccess) { NSLog(@"SDK initialization succeeded"); } else { NSLog(@"SDK initialization failed: %@", result.message); } }]; // 3. Check coverage [MTVerifySDK checkCoverageWithPhoneNumber:@"6281234567890" completion:^(MTCoverageResult *result) { if (result.isSuccess && result.isAvailable) { NSLog(@"Authentication service available, carrier: %@", result.operatorCode); } }]; // 4. Initiate authentication [MTVerifySDK startAuthenticationWithPhoneNumber:@"6281234567890" completion:^(MTAuthResult *result) { if (result.isSuccess) { NSLog(@"Authentication succeeded, Token: %@", result.token); } }];
              
              @import MTVerify;

// 1. Enable debug mode (optional)
[MTVerifySDK setDebug:YES];

// 2. Initialize the SDK
[MTVerifySDK setupWithAppKey:@"your_app_key" 
                 environment:MTEnvironmentProduction 
                  completion:^(MTSetupResult *result) {
    if (result.isSuccess) {
        NSLog(@"SDK initialization succeeded");
    } else {
        NSLog(@"SDK initialization failed: %@", result.message);
    }
}];

// 3. Check coverage
[MTVerifySDK checkCoverageWithPhoneNumber:@"6281234567890" 
                               completion:^(MTCoverageResult *result) {
    if (result.isSuccess && result.isAvailable) {
        NSLog(@"Authentication service available, carrier: %@", result.operatorCode);
    }
}];

// 4. Initiate authentication
[MTVerifySDK startAuthenticationWithPhoneNumber:@"6281234567890" 
                                     completion:^(MTAuthResult *result) {
    if (result.isSuccess) {
        NSLog(@"Authentication succeeded, Token: %@", result.token);
    }
}];

            
This code block in the floating window

API Reference

MTVerifySDK Class

MTVerifySDK is the core class of the SDK and provides all authentication-related features.

Properties

Property Type Description
version String SDK version number (read-only, class property)
isInitialized Bool Whether the SDK has been initialized (read-only, class property)

Methods

setDebug(_:)

Set debug mode; when enabled, detailed logs are output.

static func setDebug(_ enabled: Bool)
              
              static func setDebug(_ enabled: Bool)

            
This code block in the floating window

Parameters

Parameter Type Description
enabled Bool Whether to enable debug mode

Notes

  • Recommended to enable during development and testing
  • Recommended to disable in release builds
isDebug()

Get the current debug mode status.

static func isDebug() -> Bool
              
              static func isDebug() -> Bool

            
This code block in the floating window

Return Value

Bool - Whether debug mode is enabled

setup(appKey:environment:completion:)

Initialize the SDK. Use the AppKey to automatically fetch configuration from the server and complete initialization.

static func setup(appKey: String, environment: MTEnvironment = .production, completion: @escaping (MTSetupResult) -> Void)
              
              static func setup(appKey: String,
                  environment: MTEnvironment = .production,
                  completion: @escaping (MTSetupResult) -> Void)

            
This code block in the floating window

Parameters

Parameter Type Description
appKey String App AppKey, obtained from the console
environment MTEnvironment Runtime environment, defaults to .production
completion (MTSetupResult) -> Void Initialization completion callback

Notes

  • Initialization must be completed before calling other APIs
  • Initialization is an asynchronous operation; confirm success in the callback
  • Recommended to call in AppDelegate or at application launch
checkCoverage(phoneNumber:completion:)

Check whether the current network environment supports the authentication service.

static func checkCoverage(phoneNumber: String, completion: @escaping (MTCoverageResult) -> Void)
              
              static func checkCoverage(phoneNumber: String,
                          completion: @escaping (MTCoverageResult) -> Void)

            
This code block in the floating window

Parameters

Parameter Type Description
phoneNumber String Mobile number (country code + phone number)
completion (MTCoverageResult) -> Void Check completion callback

Return Result

Returned via the MTCoverageResult object:

  • isAvailable: whether authentication is supported
  • operatorCode: carrier code; ignore this field, it returns empty by default

Notes

  • Make sure the SDK is initialized before calling
  • Recommended to call this method to check coverage before initiating authentication
startAuthentication(phoneNumber:completion:)

Initiate mobile number authentication.

static func startAuthentication(phoneNumber: String, completion: @escaping (MTAuthResult) -> Void)
              
              static func startAuthentication(phoneNumber: String,
                                completion: @escaping (MTAuthResult) -> Void)

            
This code block in the floating window

Parameters

Parameter Type Description
phoneNumber String Mobile number (country code + phone number)
completion (MTAuthResult) -> Void Authentication completion callback

Return Result

Returned via the MTAuthResult object:

  • token: authentication token, used for backend verification

Notes

  • Make sure the SDK is initialized before calling
  • Must be used in a cellular network environment
  • The obtained token must be passed to the backend for secondary verification

Enumerations

MTEnvironment

SDK runtime environment enum.

@objc public enum MTEnvironment: Int { case sandbox = 0 // Sandbox environment (testing) case production = 1 // Production environment }
              
              @objc public enum MTEnvironment: Int {
    case sandbox = 0      // Sandbox environment (testing)
    case production = 1   // Production environment
}

            
This code block in the floating window
Value Description
.sandbox Sandbox testing environment
.production Production environment

Result Types

MTSetupResult

Initialization result class.

@objcMembers public class MTSetupResult: NSObject { /// Result code (0 means success, others mean failure) public let code: Int /// Description message public let message: String /// Whether successful public var isSuccess: Bool { return code == 0 } }
              
              @objcMembers
public class MTSetupResult: NSObject {
    /// Result code (0 means success, others mean failure)
    public let code: Int
    
    /// Description message
    public let message: String
    
    /// Whether successful
    public var isSuccess: Bool { return code == 0 }
}

            
This code block in the floating window
Property Type Description
code Int Result code; 0 means success
message String Description message
isSuccess Bool Whether successful (computed property)

MTCoverageResult

Coverage check result class.

@objcMembers public class MTCoverageResult: NSObject { /// Result code (0 means success, others mean failure) public let code: Int /// Description message public let message: String /// Whether available public let isAvailable: Bool /// Carrier code public let operatorCode: String? /// Whether successful public var isSuccess: Bool { return code == 0 } }
              
              @objcMembers
public class MTCoverageResult: NSObject {
    /// Result code (0 means success, others mean failure)
    public let code: Int
    
    /// Description message
    public let message: String
    
    /// Whether available
    public let isAvailable: Bool
    
    /// Carrier code
    public let operatorCode: String?
    
    /// Whether successful
    public var isSuccess: Bool { return code == 0 }
}

            
This code block in the floating window
Property Type Description
code Int Result code; 0 means success
message String Description message
isAvailable Bool Whether the current environment supports authentication
operatorCode String? Carrier code (e.g. "TELKOMSEL"); ignore this field, it returns empty by default
isSuccess Bool Whether successful (computed property)

MTAuthResult

Authentication result class.

@objcMembers public class MTAuthResult: NSObject { /// Result code (0 means success, others mean failure) public let code: Int /// Description message public let message: String /// Authentication token (used for backend verification) public let token: String? /// Whether successful public var isSuccess: Bool { return code == 0 } }
              
              @objcMembers
public class MTAuthResult: NSObject {
    /// Result code (0 means success, others mean failure)
    public let code: Int
    
    /// Description message
    public let message: String
    
    /// Authentication token (used for backend verification)
    public let token: String?
    
    /// Whether successful
    public var isSuccess: Bool { return code == 0 }
}

            
This code block in the floating window
Property Type Description
code Int Result code; 0 means success
message String Description message
token String? Authentication token, used for backend secondary verification
isSuccess Bool Whether successful (computed property)

Complete Example

Complete Swift Integration Example

import UIKit import MTVerify class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Enable debug mode MTVerifySDK.setDebug(true) // Initialize the SDK initializeSDK() } // MARK: - SDK Initialization private func initializeSDK() { MTVerifySDK.setup( appKey: "your_app_key", environment: .production ) { [weak self] result in if result.isSuccess { print("✅ SDK initialization succeeded") print("SDK version: \(MTVerifySDK.version)") print("Initialized: \(MTVerifySDK.isInitialized)") } else { print("❌ SDK initialization failed: \(result.message) (code: \(result.code))") } } } // MARK: - Check Coverage func checkCoverage(phoneNumber: String) { // Check whether the SDK is initialized guard MTVerifySDK.isInitialized else { print("⚠️ SDK not initialized") return } MTVerifySDK.checkCoverage(phoneNumber: phoneNumber) { result in if result.isSuccess { if result.isAvailable { print("✅ Service available") print("Carrier: \(result.operatorCode ?? "Unknown")") } else { print("⚠️ The current environment does not support the authentication service") } } else { print("❌ Check failed: \(result.message) (code: \(result.code))") } } } // MARK: - Initiate Authentication func authenticate(phoneNumber: String) { // Check whether the SDK is initialized guard MTVerifySDK.isInitialized else { print("⚠️ SDK not initialized") return } MTVerifySDK.startAuthentication(phoneNumber: phoneNumber) { result in if result.isSuccess { print("✅ Authentication succeeded") print("Token: \(result.token ?? "")") // TODO: Send the token to the backend for verification self.verifyTokenOnServer(token: result.token ?? "") } else { print("❌ Authentication failed: \(result.message) (code: \(result.code))") } } } // MARK: - Backend Verification private func verifyTokenOnServer(token: String) { // Send the token to your backend server for verification // The backend uses the token to call the MTVerify server API to verify the phone number } }
              
              import UIKit
import MTVerify

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Enable debug mode
        MTVerifySDK.setDebug(true)
        
        // Initialize the SDK
        initializeSDK()
    }
    
    // MARK: - SDK Initialization
    
    private func initializeSDK() {
        MTVerifySDK.setup(
            appKey: "your_app_key",
            environment: .production
        ) { [weak self] result in
            if result.isSuccess {
                print("✅ SDK initialization succeeded")
                print("SDK version: \(MTVerifySDK.version)")
                print("Initialized: \(MTVerifySDK.isInitialized)")
            } else {
                print("❌ SDK initialization failed: \(result.message) (code: \(result.code))")
            }
        }
    }
    
    // MARK: - Check Coverage
    
    func checkCoverage(phoneNumber: String) {
        // Check whether the SDK is initialized
        guard MTVerifySDK.isInitialized else {
            print("⚠️ SDK not initialized")
            return
        }
        
        MTVerifySDK.checkCoverage(phoneNumber: phoneNumber) { result in
            if result.isSuccess {
                if result.isAvailable {
                    print("✅ Service available")
                    print("Carrier: \(result.operatorCode ?? "Unknown")")
                } else {
                    print("⚠️ The current environment does not support the authentication service")
                }
            } else {
                print("❌ Check failed: \(result.message) (code: \(result.code))")
            }
        }
    }
    
    // MARK: - Initiate Authentication
    
    func authenticate(phoneNumber: String) {
        // Check whether the SDK is initialized
        guard MTVerifySDK.isInitialized else {
            print("⚠️ SDK not initialized")
            return
        }
        
        MTVerifySDK.startAuthentication(phoneNumber: phoneNumber) { result in
            if result.isSuccess {
                print("✅ Authentication succeeded")
                print("Token: \(result.token ?? "")")
                
                // TODO: Send the token to the backend for verification
                self.verifyTokenOnServer(token: result.token ?? "")
                
            } else {
                print("❌ Authentication failed: \(result.message) (code: \(result.code))")
            }
        }
    }
    
    // MARK: - Backend Verification
    
    private func verifyTokenOnServer(token: String) {
        // Send the token to your backend server for verification
        // The backend uses the token to call the MTVerify server API to verify the phone number
    }
}

            
This code block in the floating window

Version Information

  • SDK version: 1.0.1
Icon Solid Transparent White Qiyu
Contact Sales