I am working on an app for macOS. We want to use the Touch ID sensor in the new MacBook Pro’s to unlock our app. On iOS, you can test the Local Authentication framework from the simulator.
Is there a way to test Touch ID for Mac apps? The latest XCode build provides a nice Touch Bar simulator, but I cannot find anything for Touch ID.
Thanks!
Choose Apple menu > System Preferences, click Touch ID, then make sure that "Unlocking your Mac" or "iTunes Store, App Store & Apple Books" is on, and that you've added one or more fingerprints. Try to add a different fingerprint.
Fix 1: Clean the Touch ID sensor and your fingers Dirt or liquid on your finger and the Touch ID sensor may cause Mac not to read your fingerprint properly. That's likely why Touch ID seems to be working but can't recognize your fingerprints. To clean the fingerprint sensor, you can wipe it with a clean and dry cloth.
On your Mac, choose Apple menu > System Preferences, then click Touch ID . Click “Add Fingerprint,” enter your password, then follow the onscreen instructions. If your Mac or Magic Keyboard has Touch ID, the sensor is located at the top right of your keyboard.
Rick Fillion (from 1Password) was kind enough to offer some advice: https://twitter.com/rickfillion/status/794370861646172160
Use LAPolicy.DeviceOwnerAuthentication
to test.
Here’s the code I am running (Swift 2.3):
import Cocoa
import LocalAuthentication
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myContext = LAContext()
let myLocalizedReasonString = "unlock itself"
var authError: NSError? = nil
if #available(iOS 8.0, OSX 10.12, *) {
if myContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, error: &authError) {
myContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthentication, localizedReason: myLocalizedReasonString) { (success, evaluateError) in
if (success) {
// User authenticated successfully, take appropriate action
print("Success")
} else {
// User did not authenticate successfully, look at error and take appropriate action
print("Failure")
}
}
} else {
// Could not evaluate policy; look at authError and present an appropriate message to user
print("Evaluation")
print(authError)
}
} else {
// Fallback on earlier versions
print("Fallback")
}
// Do any additional setup after loading the view.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With