UnlockCodeViewController
一个简单的即插即用解锁代码视图控制器。
用法
基本用法
// Create the view controller
let viewController = UnlockCodeViewController(unlockCode: myCode)
// Present the view controller
navigationController.setViewControllers([viewController], animated: false)
// Set the unlock action (this can also be set in the constructor)
viewController.whenUnlocked { _ in
navigationController.setViewControllers([myLockedContentViewController], animated: true)
}
附加配置
// (Optional) Additional config
viewController.pinCharacter = "*" // default: "●"
viewController.blankCharacter = "_" // default: "○"
viewController.playsSound = false // default: `true`
viewController.autoDismissOnUnlock = false // default: `false`
viewController.autoDismissOnFailure = true // default: `false`
viewController.maxAttemptsAllowed = 5 // default: 3
生成解锁码
- 理想情况下,您将解锁码远程设置,并将其加载到您的应用程序中。
- 其次,最好使用预先生成的代码。否则,任何人都可以反编译您的应用程序并读取您的代码。
// Using a pre-generated code (e.g. "123456")
let myCode = UnlockCode(
hash: "2DBD6C5C6085CB173C76E0856CF2EB85DB6A464264704528187E18A808A0D569",
salt: "O%0jc@_Qy)gAa9d",
length: 6,
isNumeric: true
)
// Or generate one on the fly (*Not Recommended*)
let myGeneratedCode = UnlockCode(generateFor: "123456")
示例项目
要运行示例项目,请克隆仓库,并在 Xcode 10 或更高版本中运行。
安装
CocoaPods
UnlockCodeViewController 可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 中
pod 'UnlockCodeViewController'
作者
Reece Como,[email protected]
许可证
UnlockCodeViewController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。