Skip to content

Instantly share code, notes, and snippets.

@ghecho
Created January 29, 2015 05:22
Show Gist options
  • Save ghecho/47f071de810c375ca605 to your computer and use it in GitHub Desktop.
Save ghecho/47f071de810c375ca605 to your computer and use it in GitHub Desktop.
ViewController with Touch ID
//
// ViewController.swift
// TouchIDViewController
//
// Created by Diego on 1/28/15.
// Copyright (c) 2015 Diego. All rights reserved.
//
import UIKit
import LocalAuthentication
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func authTapped() {
var context = LAContext()
var error:NSErrorPointer = nil
if(context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: error))
{
//Touch ID Available
context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Are you the one?", reply: {
(success:Bool, error:NSError!) in
if(success)
{
self.showNotice("Hooray!!!", message:"You are the one.")
}
else
{
if(error.code == Int(kLAErrorUserFallback))
{
self.showNotice("Notice", message:"Fallback.")
}
else if(error.code == Int(kLAErrorUserCancel))
{
self.showNotice("Notice", message:"You canceled.")
}
else
{
self.showNotice("Error", message:"There was an error with the authentication.")
}
}
})
}
else
{
self.showNotice("Error", message:"Your device don't have Touch ID.")
}
}
func showNotice(title:String, message:String)
{
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
}
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment