UITextView - Enable dictation alert disappears quickly

Viewed 280

I've text view. When keyboard is showing and I tap on dictation icon it shows Enable Dictation window and then disappears quickly on a device. On simulator it works on some and not on others. I'm not sure why it's happening. I've searched but can't find any single result with similar issue.

It's not just with text view, it also happens on search bar.

This issue doesn't happen on iPhone X device.

Any clue on why it's happening and how to fix it or what to look for?

I did a test and created a new VC in my app with only text view and it also doesn't work there. This confirms that this issue has nothing to do with anything in the code. May be it is to do with some project settings?

I also see following error:

[Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=221 "(null)" UserInfo={NSUnderlyingError=0x2832cf8a0 {Error Domain=NSOSStatusErrorDomain Code=561017449 "(null)"}}
!!! _NSLayoutTreeGetBaselineOffsetForGlyphAtIndex invalid glyph index 
2 Answers

I had same problem when was using AVAudioEngine - when dictation starts the engine stops, and by starting it again (following the AVAudioSession.routeChangeNotification) I was interrupting the dictation. I had to pause the player when dictation starts:

textInputModeObserver = NotificationCenter.default.addObserver(
    forName: UITextInputMode.currentInputModeDidChangeNotification,
    object: nil,
    queue: .main) { [weak self] _ in
        guard
            let self = self,
            self.textView.textInputMode?.primaryLanguage == "dictation"
            else { return }
        self.player.pause()
}
Related