-[RTIInputSystemClient RemoteTextInputSessionWithID:performInputOperation:] 执行输入操作需要有效的 sessionID Xcode SwiftUI 中的错误

Jak*_*rer 7 xcode firebase-authentication swiftui

当我在登录屏幕中输入电子邮件和密码信息并点击“登录”或“创建帐户”时,我在应用程序中的应用程序错误消息中收到此消息,在我的控制台中我收到此消息:

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

我尝试在 StackOverflow 和 Apple Developer 论坛上搜索各种论坛,但没有看到发布任何解决方案。

  1. 在 RootView() 之后调用的身份验证视图,这是发生错误的地方
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
Run Code Online (Sandbox Code Playgroud)

如果您对可能导致此问题的原因有任何见解,或者您对代码或我已实现的任何其他视图、视图模型或模型有任何疑问,请回复。