UIKeyCommand in QLPreviewController in iOS 15

With iOS 15 there are changes to keyboard handling. Besides usual overriding of keyCommands a programmer has to assign own commands higher priority than system commands.

So, the following code works for me:

final class MyViewController: UIViewController {

    override var keyCommands: [UIKeyCommand]? {
        let action = UIKeyCommand(input: UIKeyCommand.inputUpArrow, modifierFlags: [], action: #selector(myAction))
        if #available(iOS 15, *) {
            action.wantsPriorityOverSystemBehavior = true
        }
        return [action]
    }
    // rest of the code
}

On the other hand, almost the same code but with inheriting from QLPreviewController doesn't work:

final class PreviewViewController: QLPreviewController {
    // same internals as above
}

In view hierarchy I spotted that there is actually some kind of extra navigation, maybe that is stealing my keyboard presses, maybe that's why above code isn't working.


Does anyone have an idea how to fix or workaround this issue? Obviously, the extra navigation is from Apple and I don't have access to these extra presented controllers.

I was trying to print the following details, but neither helps:

print(presentedViewController ?? "none") // output: none
print(topMostViewController) // output: <MyApp.PreviewViewController: 0x7fbe44156203>
print(inputViewController ?? "none") // output: none

It's worth to add I've also tried to add method

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test?")
    super.pressesBegan(presses, with: event)
}

And test never appears in the console, whatever button I press. So clearly something else steals the key presses. This did not happen before iOS 15.

I conclude it, thinking it may be a bug in the API. Probably just no one thought of this scenario when adding the new keys..?