SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.32k stars 746 forks source link

Alert not shown after Biometry check (only from v. 9.0.1) #466

Closed riccardoch closed 3 years ago

riccardoch commented 3 years ago

From version 9.0.1 my app can't display alert after Biometry check. This issue doesn't occur with older versions. If I try to show the alert after 1 sec (or more) using DispatchQueue.main.asynAfter the alert appears correctly.

Here the code that doesn't work:

let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
    context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
        success, authenticationError in
            if success {
                // Show an alert
                ...
                SwiftMessages.show(config: config, view: view)
            }
            else { ... }
      }
} 
else {  ... }
wtmoose commented 3 years ago

Is that callback on the main queue?

wtmoose commented 3 years ago

Also, have you tried 9.0.2?

riccardoch commented 3 years ago

@wtmoose I've tried both 9.0.1 and 9.0.2. The callback doesn't need to be on a different thread, anyway if I include it on another thread the alert is not shown.

wtmoose commented 3 years ago

I was asking if the callback is on the main queue or not. I can't tell from looking at your code.

riccardoch commented 3 years ago

It's on main queue 😉

riccardoch commented 3 years ago

I've tried with a basic message, without custom configurations, but nothing changed. The Biometry check is done after a button action (Touch Inside).

vg-identance commented 3 years ago

I have similar issue but when app return to active state. I handle Internet reachability states and show bar when Internet is not reachable. And when disable it via iOS flight mode bar is not showed. I researched it a bit and found that issue is here: https://github.com/SwiftKickMobile/SwiftMessages/blob/6925ef9f8f19ce7fef2bf3fbe4dcf5fc99d471e0/SwiftMessages/UIWindow%2BExtensions.swift#L16

Because window scene at moment when reachability status changed is not in active state (like in original case with iOS biometric) bar is not showed. I suggest to update condition or rollback to old implementation.

wtmoose commented 3 years ago

@vg-identance Yeah, I don't know why that line is there, but it doesn't belong. I'll remove it

vitalii-tym commented 3 years ago

Exactly same issue happens after opening app via universal link. In my case a universal link is handled, then REST API called, and alert is shown on fail. It looks like on current devices all these things happen really fast. I have temporarily work-arounded the issue by giving a 1 sec delay to the message without having to modify the library.

Also I have double-checked that commenting out .filter { $0.activationState == .foregroundActive } fixes the issue indeed.

zhaxling commented 3 years ago

怎么解决?我在首次启动的时候alert,同时弹出IDFA权限请求弹框,SwiftMessages没有弹出,之后再次alert也没有弹框

wtmoose commented 3 years ago

@riccardoch I'm sorry for taking so long to look at this – I was overloaded at work. The fix was a little bit more involved than commenting out .filter { $0.activationState == .foregroundActive }, but along the same lines. If you'd like to confirm, the fixes are on branch work/9.0.3.

riccardoch commented 3 years ago

@wtmoose I've tried the branch and everything work as expected. Thanks for the great work!

wtmoose commented 3 years ago

Released 9.0.3