Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you test Touch ID for macOS?

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!

iOS Simulator Touch ID testing

like image 762
Richard Burton Avatar asked Nov 04 '16 01:11

Richard Burton


People also ask

How do I know if my Touch ID is working Mac?

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.

Why is Touch ID on Mac not working?

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.

How do I activate finger ID on Mac?

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.


1 Answers

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.
    }
}
like image 141
Richard Burton Avatar answered Oct 05 '22 00:10

Richard Burton