This guide will walk you through integrating the OtplessSwiftLP
SDK in your iOS project using CocoaPods.
-
Add the following to your
Podfile
:pod 'OtplessSwiftLP'
-
Then run:
pod install
-
Open your project in Xcode.
-
Go to
File
→Add Packages...
. -
Enter the repository URL:
https://github.com/otpless-tech/iOS-LP.git
-
Choose "Exact version", select the latest version that is displayed there and click Add Package.
Add the following keys in your info.plist
file:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>otpless.{{YOUR_APP_ID}}</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>otpless</string>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
<string>otpless</string>
<string>gootpless</string>
<string>com.otpless.ios.app.otpless</string>
<string>googlegmail</string>
</array>
Import the SDK at the top of your ViewController.swift
:
import OtplessSwiftLP
Your ViewController
should conform to ConnectResponseDelegate
:
func onConnectResponse(_ response: [String: Any]) {
if let error = response["error"] as? String {
print("Error: \(error)")
} else if token = response["token"] as? String {
print("Token: \(token)")
// Send this token to your server to validate and get user details.
} else {
// Unknown error occurred
print("Unknown response: \(response)")
}
}
Set the response delegate and optionally enable socket logging:
override func viewDidLoad() {
super.viewDidLoad()
OtplessSwiftLP.shared.setResponseDelegate(self)
// Initialize SDK
OtplessSwiftLP.shared.initialize(appId: "YOUR_APP_ID", secret: "YOUR_SECRET") { success in
if success {
// SDK initialization success
}
}
}
To start the authentication process, use:
@IBAction private func startButtonTapped() {
OtplessSwiftLP.shared.start(vc: self)
}
When your login page is closed or login is successful, stop the Otpless' authentication process:
OtplessSwiftLP.shared.cease()
Make sure that initialize()
is called again if you call cease()
.
MIT © Otpless