Easily add a passcode to your iOS app
PasscodeKit is split into two modules and depending on what you need you can use the main or core module.
The default module, with UI and handling already setup. Simply add .passcode(title:hint:)
, with an optional title and hint view, to your root view.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.passcode("Enter Passcode") {
// Optional view as a hint above the code view
}
}
}
}
The passcode has to be setup by the user in order to be used, you can add this modifier to any view to start the setup.
.setupPasscode(isPresented: $setupPasscode, type: .numeric(6))
To remove the passcode again, use the environment variables to access the . You can also set the manager environment variable to override the used Keychain instance and key where the key that is used to store the data.
@Environment(\.passcode.manager) private var passcodeManager
Then simply remove the entry for the passcode
passcodeManager.delete()
The core module, that handles displaying the passcode window. By default it has no UI to enter a passcode or setting up and storing the passcode, but you can use this as a base to implement your own UI.
.passcode(mode: PasscodeMode) { dismiss in
// some Passcode input UI, call `dismiss(animated:)` once finished
} background: {
// some optional background view
}
Customize / Localize the PasscodeKit
by providing a Passcode.strings
file in your main app bundle. See the default Passcode.strings file for English Strings.
Add the following package URL to Xcode
https://github.com/divadretlaw/PasscodeKit
Select the module you need
let package = Package(
dependencies: [
.package(url: "https://github.com/divadretlaw/PasscodeKit.git", from: "0.7.0")
],
targets: [
.target(
name: <#Target Name#>,
dependencies: [
.product(name: "PasscodeKit", package: "PasscodeKit")
]
)
]
)
See LICENSE