iOS17 UITextView inputView becomFirstResponder does not work

Simplely, when we set UITextView.inputView and then call becomeFirstResponder, but the custom inputView could not show expectedly just like before. We test this code in iOS17 and below, while only iOS17 does not work.

And xcode console print these logs:

Failed to retrieve snapshot. -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked:

Post not yet marked as solved Up vote post of MatchBoxy Down vote post of MatchBoxy
26k views
  • UIView *cv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _customKBView.frame.size.width, _customKBView.frame.size.height)]; cv.backgroundColor = [UIColor blueColor]; [cv addSubview:_customKBView];

    _fakeTxtView.inputView = cv; [_fakeTxtView becomeFirstResponder];

Add a Comment

Replies

Minmal reproducible example:

import SwiftUI

struct ContentView: View {
    @State private var text: String = ""
    @FocusState private var focused: Bool

    var body: some View {
        List {
            TextField("key", text: $text)
                .focused($focused)
            if (!focused) {
                Section {
                    Button("click") {
                        print("click")
                    }
                }
            }
        }
    }
}

For some reason, if I remove one of .focused($focused), if (!focused) { or Section, the error doesn't occur.

  • This code definitely reproduces the problem. I use @FocusState a lot in my app. Be hard to lose it.

  • Further info: Xcode 15.0.1 with deployment targets of iOS 16 or iOS 17 this is problem. Simulators and actual devices all exhibit this behavior for me.

  • For me, using XCode 15.1 and Simulator 15.1, the minimum reproducible code is this:

    import SwiftUI

    struct ContentView: View { @State private var text: String = ""

    var body: some View {
        TextField("Test", text: $text)
    }
    

    }

    #Preview { ContentView() }

    Clicking the text field once will generate a couple of Error for queryMetaDataSync: 2 errors, it won't show the keyboard and later will show a flurry of other errors (can't paste here due to comment size limit)

Add a Comment

Hello there! I had the same error. In my case the problem was in a LazyVStack in which I had the TextField. I changed from LazyVStack to Stack and everything is fine. Probably this occur because of the resizing of the container.

Same issue here, but... i found a solution !

I tried to disable IQKeyboardManager for the classes where the problem appeared. And it worked !

I updated to IQKeyboardManagerSwift and its still OK.

Same error with Xcode 15.0.1. With some additional log:

Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem.
If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable.

Please fix this problem.

I guess this is Apple speaking to Apple… 😉

  • I have the exact situation you describe.

  • @apple team same issues for me on textfield -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID CAReportingClient.mm:532 Attempted to remove a reporter not created by this client { careporter_id=4,174,708,211,716 }

Add a Comment

This may be related to this post: https://developer.apple.com/forums/thread/738726 where the appearance of text magnification loupe, text selection pop ups or autocorrect suggestions cause the error.

+1

I am also seeing this - I am wondering if it's effecting a ToolbarItemGroup from displaying incorrectly - intermittently.

+1 -- same issue here as well.

+1, I'm having the same issue

Same issue for me, running on iOS 17 (iPhone 14 Pro Max), iOS 16 (iPhone X), and iOS 17 Simulators. Using Xcode 15.0.1

+1 The same issue. React Native project: xCode 15, ios 17, simulatore. Real device is passed this.

+1, I'm having the same issue with iOS 17, Xcode 15.0.1, SwiftUI and TextField

Work fine with iOS 16

  • Trace in Xcode: [RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID

Add a Comment

+1, I'm having the same issue

Not sure if this will help some but for me I was getting this message with a WKWebView that was editable when trying to show the keyboard. It was looping endlessly. I finally managed to remove the error and use the keyboard by removing an environment variable that I had in the view that contained the WKWebView Representable. It was the following @Environment(.colorScheme) var colorScheme. Commenting this out removed the problem.

I was struggling with the same error:

-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID

My workaround is using UITextFieldDelegate.

I created a new string variable in my view controller, and then set my text field's delegate to self.

class ViewController : UIViewController {

    private var textFieldText : String? = nil

    private var myTextField : UITextField = {
    //....... some code
    }()

    override func viewDidLoad() {
        //....... some code
        myTextField.delegate = self
    }
}

Then i set this new string to text field's text after editing ends with the delegate method.

extension AddToGalleryVC: UITextFieldDelegate {
    func textFieldDidEndEditing(_ textField: UITextField) {
        let text = textField.text
        textFieldText = text
    }
}

So i am using my new variable (textFieldText) instead of myTextField.text

Maybe an ugly solution but works for now.