Enable dictation alert disappears quickly

I'm facing a weird situation in my app. When keyboard shows up and I click on microphone icon for dictation, the "Enable Dictation?" alert shows up but disappears quickly before I can tap on any option. How do I find out what is wrong in my code or how do I fix it?

When the "Enable Dictation?" alert is displayed, appDelegate.applicationWillResignActive() is called. My guess is that in this method, you are force-ending the editing of the text input (via endEditing(), resignFirstResponder(), etc.) which is making the need for dictation permission no longer necessary.

Following up on @spencer602's comment: in my case, in a SwiftUI app, a `.blur()' modifier applied on a close-to-root view / root view was making the 'Enable dictation' alert disappear when tapping the microphone button on the keyboard. So I think a general recommendation for cases where the 'Enable dictation' alert disappears would be the following: check app related callbacks (willResignActive, didEnterBackground) for any first responder manipulation, if that's not the case, make sure you are not altering the view hierarchy in any way when app resigns active / goes into background.

Enable dictation alert disappears quickly
 
 
Q