A simple drop-in Unlock Code view controller.
// 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
- Ideally you would set the unlock code remotely, and load it into your app.
- Then next best option would be to use a pre-generated code. Otherwise anyone can decompile your application and read your code in plaintext.
// 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")
Complete documentation is available online.
To run the example project, clone the repo, and run in Xcode 10 or greater.
UnlockCodeViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'UnlockCodeViewController'
Reece Como, reece.como@gmail.com
UnlockCodeViewController is available under the MIT license. See the LICENSE file for more info.