onKeyPress not working on iOS/iPadOS 17.4 but fine on macOS

According to a post on hackingwithswift.com, this should work on iOS/iPadOS:

import SwiftUI

struct ContentView: View {
    @FocusState private var focused: Bool
    @State private var key = ""
    
    var body: some View {
        Text(key)
            .focusable()
            .focused($focused)
            .onKeyPress { press in
                key += press.characters
                return .handled
            }
            .onAppear {
                focused = true
            }
    }
}

It does not work for me using a hardware keyboard on an iPad running the latest iPadOS 17.4 beta but it does work on my Mac.

FB13644182

The FocusState cannot be updated on iPadOS devices whilst the physical keyboard is attached. You can see the same behaviour with sims where unticking the "Connect Hardware Keyboard" option allows the state to be set and then ticking it allows it to work.

See these two links from other developers experiencing the same limitations:

onKeyPress not working on iOS/iPadOS 17.4 but fine on macOS
 
 
Q