-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID Error in Xcode SwiftUI
Asked Answered
M

4

23

When I enter email and password information in my Login screen and tap either "Log in" or "Create Account" I get this message in my app error message in app and in my console I am receiving this message:

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

I have tried searching various forums on StackOverflow and Apple Developer forums but I have not seen any solution posted.

  1. Authentication View that is called after the RootView(), this is where the error is occurring
import SwiftUI
import Combine

struct IdentifiableError: Identifiable {
    let id = UUID()
    let message: String
}

struct AuthView: View {
    @ObservedObject var viewModel: JobApplicationViewModel
    @State private var email: String = ""
    @State private var password: String = ""
    @State private var storedEmail: String = "" // Separate variable to hold the email
    @State private var storedPassword: String = "" // Separate variable to hold the password
    @State private var showingLogin = false
    @State private var showingCreateAccount = false
    @State private var identifiableError: IdentifiableError?
    @FocusState private var isInputActive: Bool // For iOS 15+

    var body: some View {
        VStack {
            Image(systemName: "briefcase.fill")
                .resizable()
                .scaledToFit()
                .frame(width: 120, height: 120)
                .padding()

            Text("Welcome to Job Tracker Pro")
                .font(.largeTitle)

            TextField("Email", text: $email)
                .autocapitalization(.none)
                .keyboardType(.emailAddress)
                .disableAutocorrection(true)
                .padding()
                .border(Color.gray)
                .onChange(of: email) { [email] in
                    storedEmail = email
                }
                .onSubmit {
                    storedEmail = email // Store the email when submit the field
                }
            
            SecureField("Password", text: $password)
                .padding()
                .border(Color.gray)
                .onChange(of: password) { [password] in
                    storedPassword = password
                }
                .onSubmit {
                    storedPassword = password // Store the password when submit the field
                }
            
            Button("Log In") {
                hideKeyboard() // Dismiss the keyboard
                // Use storedEmail and storedPassword to log in
                // If you're handling login directly in AuthView
                viewModel.logIn(email: storedEmail, password: storedPassword) { success, message in
                    // Handle completion
                }

                showingLogin = true
            }
            .padding()

            Button("Create Account") {
                hideKeyboard() // Dismiss the keyboard
                // Use storedEmail and storedPassword to create an account
                // If you're handling account creation directly in AuthView
                viewModel.createAccount(email: storedEmail, password: storedPassword) {    success, message in
                        // Handle completion
                }
                
                showingCreateAccount = true
            }
            .padding()
        }
        .alert(item: $identifiableError) { error in
            Alert(
                title: Text("Error"),
                message: Text(error.message),
                dismissButton: .default(Text("OK")) {
                    identifiableError = nil
                }
            )
        }
        .onReceive(viewModel.$error) { error in
            if let error = error {
                identifiableError = IdentifiableError(message: error.localizedDescription)
            }
        }
    }
}

#if canImport(UIKit)
extension View {
    func hideKeyboard() {
        UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
#endif

Please reply back if you have any insight on what might be causing this or if you have any questions about the code or any other views, view models, or models that I have implemented.

Majors answered 11/1 at 13:39 Comment(4)
May not be related, but what happens if UIKit cannot be imported, you still call hideKeyboard() in your Buttons. Try wrapping #if canImport(UIKit) around the UIApplication.shared.... not the extension ViewSilk
it is caused by the FocusState on iOS 17. Gotta wait for Apple I guess.Spiral
@Spiral - Is this just an issue with FocusState and .focused modifier in general? I'm attempting to use FocusState in conjunction with a ToolbarItem(placement: .keyboard) with a button to dismiss the keyboard. Just wondering if you have any further information on FocusState issues in iOS17 and if they are resolved in iOS 17.4Basrelief
I can confirm it has not been resolved in iOS 17.4. There is a work-around for dismissing. Focus on a textfield outside the toolbar and check if it came from the toolbar textfield. If so set focusedfield to nil. The keyboard will be dismissed.Zipah
L
1

It is a different problem for me, but with the same error.

In react-native I'm using the "expo-image-picker".

I had been incorrectly calling the ImagePicker.launchImageLibraryAsync function in React Native. Here's my initial approach:

ImagePicker.launchImageLibraryAsync(
  {
    base64: true,
    mediaTypes: 'Images',
    quality: 0.5,
    allowsEditing: true,
    aspect: [4, 3],
  },
  (response) => {
    console.log('response: ', response);
    onFecthingImage(response);
  },
);

The correct approach involves using promises instead of a callback. Here's the corrected code:

ImagePicker.launchImageLibraryAsync(
  {
    base64: true,
    mediaTypes: 'Images',
    quality: 0.5,
    allowsEditing: true,
    aspect: [4, 3],
  }
).then((response) => {
  onFecthingImage(response);
}).catch((e) => {
  console.error('Error saving photo in launchImageLibraryAsync : ', e.message);
});

Now the "RTIInputSystemClientremoteTextInputSessionWithID:performInputOperation" error is gone.

Lamination answered 30/5 at 11:56 Comment(0)
T
0

Your FocusState should be optional enum. See Apple documentation. If you set focused(focusStateName, equals: .case) and then somewhere { focusStateName = nil }, the warning is away.

Tony answered 15/7 at 13:17 Comment(1)
I tried this but still get the warning. The warning seems to appear after the second re-focus of the text field.Fides
G
0
-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:]  perform input operation requires a valid sessionID. 
inputModality = Keyboard, 
inputOperation = <null selector>, customInfoType = UIEmojiSearchOperations

It shows on console when Scene: iOS17 + ScrollView + LazyVStack + Textfields. (iOS16 working as expected). When clicking on text field cursor appears and immediately disappears.

Solution: Replace LazyVStack with VStack solved my problem. But the log is still there.

Grunter answered 17/7 at 6:8 Comment(0)
B
0

To handle this warning add your Textfield and content inside ScrollView

struct AuthView: View {
@State private var email = ""
  var body: some View {
      ScrollView(showsIndicators:false){
          VStack{
              TextField("Email", text: $email)
                    .padding()
                    .background(Color(.systemGray6))
                    .cornerRadius(8)
                    .padding(.horizontal)
              Spacer()
              
              Button{
                  
              }label: {
                    Text("Continue")
                        .font(.headline)
                        .foregroundColor(.white)
                        .frame(maxWidth:.infinity)
                        .frame(height: 48)
                        .background(Color.blue)
                        .cornerRadius(8)
                        .padding(.horizontal)
              }
          }
          
                
      }
  }

}

and if you want to make your ScrollView fill the view add it inside a GeometryReader.

struct AuthView: View {
@State private var email = ""
  var body: some View {
      GeometryReader { proxy in  /// add this 
          ScrollView(showsIndicators:false){
              VStack{
                  TextField("Email", text: $email)
                      .padding()
                      .background(Color(.systemGray6))
                      .cornerRadius(8)
                      .padding(.horizontal)
                  Spacer()
                  
                  Button{
                      
                  }label: {
                      Text("Continue")
                          .font(.headline)
                          .foregroundColor(.white)
                          .frame(maxWidth:.infinity)
                          .frame(height: 48)
                          .background(Color.blue)
                          .cornerRadius(8)
                          .padding(.horizontal)
                  }
              }.frame(minHeight: proxy.size.height) /// add this
              
              
          }
      }
  }}
Bali answered 26/7 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.