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