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
.