I use the following code to authenticate user in my application
let mycontext = LAContext()
let authenticatonString = ""
var authError :NSError? = nil
if #available(OSX 10.12, *) {
if mycontext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
mycontext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: authenticatonString, reply: { (sucess, evaluationError) in
if sucess == true {
self.resultLabel.stringValue = "authenticated successfully"
} else {
print("error reason : \(evaluationError?.localizedDescription)")
self.resultLabel.stringValue = (evaluationError?.localizedDescription)!
}
})
} else {
self.resultLabel.stringValue = "touch id not available; so show passcode dialog"
}
} else {
self.resultLabel.stringValue = "older version of osx; so show passcode dialog"
}
Event though the touch id methods are available from osx 10.12, the canEvaluatePolicy
methods crashed in osx 10.12 and 10.12.1 with error
Error Domain=com.apple.LocalAuthentication Code=-1001 "Unknown policy: '1'" UserInfo={NSLocalizedDescription=Unknown policy: '1'}
The LAPolicy.deviceOwnerAuthenticationWithBiometrics
is also available from 10.12
I'd like to know what is going wrong with the evaluation