9

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Richard Burton
  • 2,230
  • 6
  • 34
  • 49

1 Answers1

7

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.
    }
}
Richard Burton
  • 2,230
  • 6
  • 34
  • 49