1
func authenticateBiometry(completion: @escaping ErrorHandler) {
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: " ") { success, error in
            guard let error = error else {
                if success {
                    completion(nil)
                }
                return
            }
            completion(error)
    }
}

But it prompts for touchId/faceId only the first time. What can I do to ask for it for example every time when I tap button? Let's say every 15 seconds.

halfer
  • 19,824
  • 17
  • 99
  • 186
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • 1
    just off the top of my head - if the method above is called on the button tap, did you try resetting the context at the beginning of the method? `let context = LAContext()` – stackich Oct 13 '22 at 06:55
  • @stackich, yes it works... but is there any other way? This one is ugly and in my opinion it should not work like this. – Bartłomiej Semańczyk Oct 13 '22 at 07:01

1 Answers1

2

Just tested locally and it works for me, this is the only way I found. I saw your comment above but I will put an answer here because probably someone will not find it ugly haha :).

I took some time to google some kind of reset method in LAContext class, but didn't find anything.

The solution was to reset the LAContext at the beginning of the method called on button tap:

func authenticateBiometry(completion: @escaping ErrorHandler) {
    context = LAContext() //THIS, implying that context is declared as `var`
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: " ") { success, error in
            guard let error = error else {
                if success {
                    completion(nil)
                }
                return
            }
            completion(error)
    }
}

You will be able to prompt face/touch ID on each button click, as soon as one ends.

stackich
  • 3,607
  • 3
  • 17
  • 41