Hi, how can you authenticate a User through Biometrics with iPhone Passcode as Fallback in the Autofill Credential Provider Extension?
In the App it works without a problem. In the Extension I get "Caller is not running foreground" Yeah, it isn't, as it's just a sheet above e.g. Safari.
I'd like to avoid having the user setup a Passcode dedicated to my App, especially because FaceID is way faster.
Does anybody know how to achieve iOS native Auth in the extension? Please let me know, a code sample would be appreciated.
Regards, Mia
I fixed it. I first added a delay through DispatchQueue.main.asyncAfter of .3 seconds. That fixed it while no debugger was attached. I was worried that on slower devices it still might fail, so I looked further. The problem seems to be, that .onAppear got called before it was fully in foreground. So LocalAuthentication was technically right that it wasn't at the time it was called.
I now use the following modifier
struct ViewVisibilityModifier: ViewModifier {
let onAppeared: () -> Void
func body(content: Content) -> some View {
content
.background(ViewVisibilityDetector(onAppeared: onAppeared))
}
}
struct ViewVisibilityDetector: UIViewRepresentable {
let onAppeared: () -> Void
func makeUIView(context: Context) -> UIView {
let view = UIView()
return view
}
func updateUIView(_ uiView: UIView, context: Context) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.onAppeared()
}
}
}
extension View {
func onViewDidAppear(perform action: @escaping () -> Void) -> some View {
self.modifier(ViewVisibilityModifier(onAppeared: action))
}
}
on my SwiftUI View.
BlockingView()
.onViewDidAppear {
guard !isAuthenticated else { return }
authenticate()
}
Now it gets only called once it's fully open. Such it also works while Debugging. I hope that it now covers all cases from slow devices to slow debugging sessions.