Skip to main content
Version: Java

Glide Number Verify SDK iOS Quickstart

Overview

This guide demonstrates how to integrate the Glide Number Verify SDK into your iOS app to verify phone numbers.

Prerequisites

  • Xcode 14 or later
  • Apple Developer Account
  • iOS Device or Simulator with internet connection
  • Glide Client ID (registration guide)
  • Backend Server URL You can deploy the backend by following our Number Verify Web Quickstart, which includes backend deployment instructions.

Installation

Cocoapods

Cocoapods is a dependency manager for Swift projects. To use GlideSwiftSDK with CocoaPods, add it in your Podfile.

pod 'GlideSwiftSDK'

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. To use GlideSwiftSDK with Swift Package Manger, add it to dependencies in your Package.swift

dependencies: [
.package(url: "https://github.com/ClearBlockchain/GlideSwiftSDK.git")
]

Integration

Firstly, import GlideSwiftSDK.

import GlideSwiftSDK

Second, configure the SDK, recommended in didFinishLaunchingWithOptions in AppDelegare.swift.

Glide.configure(clientId: <CLIENT_ID>, redirectUri: <REDIRECT_URI>)

Third, authenticate wherever you need.

Glide.instance.startVerification (state: <STATE>, phoneNumber: <PHONE_NUMBER>) { code, state in
}

Last step, make a request to your backend with the code that you got

let postData = PostData(code: code, phoneNumber: textInput)
let jsonData = try! JSONEncoder().encode(postData)

let url = URL(string: <YOUR_VERIFY_NUMBER_BACKEND_URL>)!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData

URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error.localizedDescription)")
return
}

guard let data = data else {
print("No data received")
return
}
let responseString = String(data: data, encoding: .utf8)
textToDisplay = (responseString ?? "err")
}

Complete Example

import SwiftUI
import SwiftData
import GlideSwiftSDK

struct PostData: Encodable {
let code: String
let phoneNumber: String
}

struct TestView: View {
@State private var textToDisplay = "init"
@State private var textInput = "+555123456789"
let verifyNumberUrl = ProcessInfo.processInfo.environment["VERIFY_NUMBER_URL"] ?? ""
var body: some View {
VStack {
TextField("insert number", text: $textInput).textFieldStyle(.roundedBorder).padding()
Button("verify number") {
let state = NSUUID().uuidString;
Glide.instance.startVerification(state: state, phoneNumber: textInput) { (code: String, state: String) in
textToDisplay = code
let postData = PostData(code: code, phoneNumber: textInput)
let jsonData = try! JSONEncoder().encode(postData)

let url = URL(string: verifyNumberUrl)!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData

if let JSONString = String(data: jsonData, encoding: String.Encoding.utf8) {
print(JSONString)
}

URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error.localizedDescription)")
return
}

guard let data = data else {
print("No data received")
return
}
let responseString = String(data: data, encoding: .utf8)
print(responseString ?? "")
textToDisplay = (responseString ?? "err")
}.resume()
}
}
Text(textToDisplay)
}

}
}

Additional Considerations

  • Error Handling: Implement proper error handling to catch and display errors to the user.
  • User Interface: Design a user-friendly UI to collect the phone number and display verification status.
  • Backend Integration: Ensure your backend server is configured to handle verification requests and send appropriate responses.
  • User Experience: Provide clear feedback to the user during the verification process.
  • Security: Protect your Glide Client ID and Backend Server URL.

By following these steps and considering the additional points, you can effectively integrate the Glide Number Verify SDK into your iOS app to enhance user security and verification processes.