The official Swift SDK for Mslm APIs.
- Xcode 14.1 (or later)
- Swift 5.2 (or later)
Mslm's APIs require an API key. If you don't have one, please read Authentication to understand how to get an API key before continuing.
For the Mslm Swift SDK, you can pass the API key via MslmApiKey
in info.plist
file.
See below for details about the installation method. Where
available, it's recommended to install any libraries with a Swift
suffix to get the
best experience when writing your app in Swift.
Instructions for Swift Package Manager support can be found in the SwiftPackageManager.md Markdown file.
Let's go through how to start using the Mslm Swift SDK with sample code.
In your Swift file, import the library at the beginning of the file:
import Mslm
Create an instance of the Mslm
class to use the entire Mslm SDK:
let mslm = Mslm()
Sending OTP:
// - Parameters:
// - phoneNumber: The phone number to which the OTP will be sent.
// - templateSMS: The template for the SMS containing the OTP.
// - tokenLength: The length of the OTP token.
// - expireSeconds: The expiration time of the OTP in seconds.
mslm.otp.send(phoneNumber: "+123456789", templateSMS: "Your OTP is", tokenLength: 6, expireSeconds: 60) { result in
switch result {
case .success(let response):
// Handle successful OTP sending response
print("OTP Sent Successfully!")
case .failure(let error):
// Handle error
print("Error sending OTP: \(error.localizedDescription)")
}
}
Verifying OTP:
// - Parameters:
// - phone: The phone number to which the OTP was sent.
// - token: The OTP token to be verified.
// - consume: A flag indicating whether to consume the token after verification (default is `true`).
mslm.otp.verify(phone: "+123456789", token: "123456") { result in
switch result {
case .success(let response):
// Handle successful OTP verification response
print("OTP Verified Successfully!")
case .failure(let error):
// Handle error
print("Error verifying OTP: \(error.localizedDescription)")
}
}
mslm.emailVerify.singleVerify("[email protected]") { result in
switch result {
case .success(let data):
// Handle successful email verification response
print("Email Verified Successfully!")
case .failure(let error):
// Handle error
print("Error verifying email: \(error.localizedDescription)")
}
}
Selecting the Mslm package installs the full suite of Mslm products. If you only need specific functionalities (e.g., OTP or EmailVerify), you can choose individual products to minimize dependencies.
- Import
OTP
in your swift file.
import OTP
- Make a call to the OTP
// Example function for sending OTP
OTP.default.send(phoneNumber: "+123456789", templateSMS: "Your OTP is", tokenLength: 6, expireSeconds: 60) { result in
switch result {
case .success(let response):
// Handle successful OTP sending response
print("OTP sent successfully!")
case .failure(let error):
// Handle error
print("Error sending OTP: \(error.localizedDescription)")
}
}
- Import
EmailVerify
in your swift file.
import EmailVerify
- Make a call to the EmailVerify
// Example function for email verification
EmailVerify.default.singleVerify("[email protected]") { result in
switch result {
case .success(let data):
// Handle successful email verification response
print("Email verified successfully!")
case .failure(let error):
// Handle error
print("Error verifying email: \(error.localizedDescription)")
}
}
See the official API Reference Documentation for details on each API's actual interface, which is implemented by this SDK.
See CONTRIBUTING for more information.
See Security Issue Notifications for more information.
This project is licensed under the MIT License.
At Mslm, we're all about making things better. Where others see norm, we see opportunity.
We build world-class solutions to the toughest problems. Excellence is a core value that defines our approach from top to bottom.
We're all about creating positive value for ourselves, our partners and our societies.
We do it by focusing on quality and the long-term, while intelligently maneuvering the complex realities of day-to-day business.
Our partners share our perspective, and we jointly produce truly world-class solutions to the toughest problems.