Post

Replies

Boosts

Views

Activity

Reply to LocalAuthentication (Alternative) in Autofill Credential Provider extension
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.
Topic: Privacy & Security SubTopic: General Tags:
Mar ’25
Reply to LocalAuthentication (Alternative) in Autofill Credential Provider extension
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
Topic: Privacy & Security SubTopic: General Tags:
Mar ’25
Reply to WKWebView Contextmenu-Item “Download Image” triggers nothing
thats the current downloaddelegate. it worked for smaller downloads. I now implemented a workaround that doesn‘t include the context menu anymore and also works for large downloads. but it doesnt get triggered when the context menu item is used. even a custom context menu item didn’t trigger anything I could see class DownloadDelegate: NSObject, WKDownloadDelegate { func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String) async -> URL? { if let downloadsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first { let url = downloadsURL.appendingPathComponent(suggestedFilename) return url } return nil } }
Topic: Safari & Web SubTopic: General Tags:
Dec ’24