This guide will walk you through integrating the OtplessSwiftConnect SDK in your iOS project using CocoaPods.
-
Add the following to your
Podfile:pod 'OtplessSwiftConnect'
-
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.
Import the SDK at the top of your ViewController.swift:
import OtplessSwiftConnectYour 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()
OtplessSwiftConnect.shared.setResponseDelegate(self)
// Initialize SDK
OtplessSwiftConnect.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() {
OtplessSwiftConnect.shared.start(vc: self)
}MIT © Otpless