How can you check Touch ID for macOS?

I am working on an application for macOS. We want to use the Touch ID sensor in the new MacBook Pro to unlock our application. On iOS, you can test the local authentication environment using a simulator.

Is there a way to check Touch ID for Mac apps? The latest version of Xcode provides a good Touch Bar simulator, but I can not find anything for Touch ID.

Thank!

iOS Simulator Touch ID testing

+4
source share
1 answer

Rick Fillion (from 1Password) was kind enough to offer some tips: https://twitter.com/rickfillion/status/794370861646172160

Use LAPolicy.DeviceOwnerAuthenticationfor testing.

, (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.
    }
}
+3

Source: https://habr.com/ru/post/1659780/


All Articles