OtpSecure Swift SDK
这个 Swift 库允许您使用 Swift 代码快速轻松地验证通过 OtpSecure Service 发送的 otp。
设置
先决条件
安装此软件所需的东西
- Swift 5.0
- Xcode 10.2
安装
使用 Cocoapods
将以下 pod 添加到您的 Podfile
pod 'OtpSecure', '2.0.0'
使用 Carthage
在您的 Cartfile 中添加以下语句:
github "ecertic/otpsecure-swift" "2.0.0"
用法
为了使用这个库,开发者必须使用 OtpSecure
模块,该模块暴露了通过令牌获取操作信息以及验证令牌的功能。
import OtpSecure
OtpSecure.retrieveOperationInfoByToken
使用 您可以使用以下示例代码来获取操作信息。Sample-app 也包含了如何使用它的示例。
OtpSecure.retrieveOperationInfoByToken(token: "INSERT_YOUR_TOKEN_HERE", completionHandler: {
result in
switch result {
case .success(let operationInfo):
// Add your logic here
case .failure(let error):
// Handle the error here
}
})
OtpSecure.validateToken
使用 您可以使用以下示例代码校验一个令牌。Sample-app 包含使用方法的示例。
OtpSecure.validateToken(token: "INSERT_YOUR_TOKEN_HERE", otp: "INSERT_THE_OTP_HERE", completionHandler: {
result in
switch result {
case .success(let validation):
// Add your logic here
case .failure(let error):
// Handle the error here
}
})
示例应用
此仓库在 Examples
文件夹中包含一个示例应用。要运行示例项目,执行以下命令
使用 Cocoapods
cd /path/to/otpsecure-swift/Examples/OtpSecureShowcase && pod install
使用Carthage
cd /path/to/otpsecure-swift/Examples/OtpSecureShowcase && carthage update
然后打开文件 OtpSecureShowcase.xcworkspace
并用所需的模拟器运行项目。
许可证
该项目许可协议为MIT - 详细信息请参阅LICENSE.md 文件。