Created
March 22, 2016 11:39
-
-
Save hansemannn/c3f65193cbe8f904a6ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import UIKit | |
| import LocalAuthentication | |
| public class TiTouchId { | |
| var context: LAContext? | |
| init() { | |
| context = LAContext() | |
| } | |
| func isSupported() -> Bool { | |
| var error: NSError? | |
| let currentOSSupported: Bool = UIDevice.currentDevice().systemVersion.compare("8.0", options: .NumericSearch) != .OrderedAscending | |
| let touchIDSupported: Bool = context!.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error) | |
| return currentOSSupported && touchIDSupported | |
| } | |
| func authenticate(reason: String, callback: (NSMutableDictionary) -> ()) -> Void { | |
| context?.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: {(success, error) in | |
| callback([ | |
| "success": success, | |
| "error": (error?.localizedDescription)!, | |
| "code": (error?.code)! | |
| ]) | |
| }) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let touchId = TiTouchId() | |
| if (touchId.isSupported()) { | |
| touchId.authenticate("Please verify to continue", callback: {(attrs) in | |
| let success: Bool = attrs.valueForKey("success") as! Bool | |
| NSLog("Success - %d", success) | |
| if ((attrs.valueForKey("error")) != nil) { | |
| NSLog("Error - %@", attrs.valueForKey("error") as! String) | |
| NSLog("Code - %lu", attrs.valueForKey("code") as! Int) | |
| } | |
| }) | |
| } else { | |
| NSLog("Touch ID is not supported on this device") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment