Clicky

iOS Dev Nugget 155 Authentication Using Touch ID

.

Need to run a code review on your codebase? Hire me

Introduced in iOS 8, being able to use Touch ID for your app's authentication is a very handy feature for users. This is especially nice to integrate because Touch ID has become very fast in iPhone 6s and iPhone 6s Plus (just released as of writing).

It is easy to integrate:

NSError* error;
LAContext* context = [[LAContext alloc] init];
BOOL canUseTouchID = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                        error:&error];
if (canUseTouchID) {
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
        localizedReason:NSLocalizedString(@"Log in with Touch ID", @"")
        reply:^(BOOL result, NSError* error) {
            if (result && !error) {
                //User authenticated, OK!
            } else {
                //Check and error
            }
        }];
} else {
    //Authenticate in another way
}

Remember to wrap Touch ID access (as well as your own code after the user is authenticated, if necessary) in the main thread and you are good to go!


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues