A reusable passcode subsystem for iOS apps. This is used as a passcode foundation by Appstronomy for our own internal and client projects. We wanted to share our solution to a common need.
Originally built in Objective-C, this framework will also work well in your Swift based apps, as demonstrated by our example Swift app bundled with this repo. The example app shows you how you might use the APPSPasscode framework, including how to customize it.
The following animation takes you through the capabilities of the Example app bundled inside this repo. Here, you'll see the default and custom visual styles.
On the iPad, the component still uses iPhone sized controls, centered on the iPad screen. Here's an example of that from the PK-PD Compass app for clinicians. It's also another example of the custom styling that's possible.
You can change the visual appearance of the passcode (lines, colors, images) as suits the needs of your app. While the default style mimics Apple's own native iOS passcode control, we don't recommend you ship using that default style. It's only an example to provide you with a familiar starting point.
We learned the hard way that your app can be rejected for presenting a passcode control that is too close to Apple's own.
Consequently, we built a generic way to style the passcode component. This way, it can take on the look of the host app it is serving. And passing App Review is also a worthy goal! :)
In the Example app in this repo, you'll see the default style and a custom style.
To configure a visual style to your liking, you'll create an instance of APPSPasscodeViewConfiguration
and set this to be the viewConfiguration
on the APPSPasscodeViewController
.
Here's an example from the bundled Example app, in Swift. It is taken from the DemoPasscodeService.swift
:
var configuration: APPSPasscodeViewConfiguration?
if passcodeStyle == .Custom {
configuration = APPSPasscodeViewConfiguration()
configuration!.topToLogoSpacing = 30
configuration!.logoToInstructionLabelSpacing = 30
configuration!.rootViewBackgroundColor = UIColor.lightGrayColor()
configuration!.messageContainerBackgroundColor = UIColor.lightGrayColor()
configuration!.keypadBackgroundColor = UIColor.lightGrayColor()
configuration!.keypadBackgroundColor = UIColor.grayColor()
configuration!.keypadNumericKeyDefaultColor = UIColor.grayColor()
configuration!.keypadNumericKeyHighlightColor = UIColor.darkGrayColor()
configuration!.keypadTextColor = UIColor.whiteColor()
configuration!.bulletColor = UIColor.darkGrayColor()
}
let passcodeController = APPSPasscodeViewController()
passcodeController.viewConfiguration = configuration
The easiest way to use APPSPasscode in your app is to add it as a Carthage dependency.
Add the following entry to your app project's Cartfile
:
github "appstronomy/APPSPasscode"
If you open up the APPSPasscode.xcodeproj
project file, you'll see just the APPSPasscode framework.
If instead, you open up the APPSPasscode.xcworkspace
workspace file, you'll see the APPSPasscode framework and an Example app that demonstrates how you might use it.
The APPSPasscode framework has an embedded dependency on the Lockbox utility class. As such, you do not have to worry about carthage or cocoapod dependencies of this framework when you pull it into your projects.
That said, you can ignore that default dependency and choose to use another tool or mechanism to store a user's passcode.
The original passcode subsystem was built for Appstronomy by Chris Morris in 2014.
Later enhancements were made by Ken Grigsby and Sohail Ahmed. UI/UX guidance was provided by Salman Sajid throughout integration in client projects (snazzier styling that unfortunately, we cannot bundle for you in this repo).