Adding Touch ID Authentication in iOS 8

It has now become very easy to ensure the person using your app is the owner of the iOS device it is running on. To add this takes only a few lines of code.

TouchId

partial void LoginPressed (UIButton sender)
{
   var context = new LAContext ();

   var error = new NSError ();
   if (context.CanEvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error)) {
      var replyHandler = new LAContextReplyHandler((success, err) => {
         this.InvokeOnMainThread(() => {
            if(success){
               Console.WriteLine("You Logged in");
            } else {
               var errorAlertView = new UIAlertView("Login Error", err.LocalizedDescription, null, "Close");
               errorAlertView.Show();
            }
         });
      });
      context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "You need to login", replyHandler);
   }
}

That’s all there is to it! The power and security of fingerprint authentication all wrapped up in a simple API.

you can grab the same project here

Advertisements

One thought on “Adding Touch ID Authentication in iOS 8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s