func authenticate(withPasscode: Bool = false) {
let context = LAContext()
var error: NSError?
let reason = "You need to unlock to access your credentials"
guard !withPasscode else {
authenticateWithPasscode()
return
}
// check whether biometric authentication is possible
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
guard authenticationError == nil else {
tryCode = true
authenticateWithPasscode()
return
}
if success {
isUnlocked = true
tryCode = false
} else {
tryCode = true
authenticateWithPasscode()
}
}
} else {
tryCode = true
authenticateWithPasscode()
}
func authenticateWithPasscode() {
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { completed, authenticationError in
if completed {
isUnlocked = true
tryCode = false
}
}
}
}
Thats the code I use on the App’s Side
If I print authenticationError in the callback from the Biometric authentication in the Extension, I get “Caller is not running foreground"
I hope that addition may help