当我在登录屏幕中输入电子邮件和密码信息并点击“登录”或“创建帐户”时,我在我的应用程序中收到此消息应用程序中的错误消息并且在我的控制台中我收到此消息:
-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID
我尝试在 StackOverflow 和 Apple Developer 论坛上搜索各种论坛,但没有看到任何解决方案。
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
如果您对可能导致此问题的原因有任何见解,或者如果您对代码或我实现的任何其他视图、视图模型或模型有任何疑问,请回复。
这对我来说是一个不同的问题,但有同样的错误。
在react-native中,我使用“expo-image-picker”。
我错误地调用了 React Native 中的 ImagePicker.launchImageLibraryAsync 函数。这是我最初的方法:
ImagePicker.launchImageLibraryAsync(
{
base64: true,
mediaTypes: 'Images',
quality: 0.5,
allowsEditing: true,
aspect: [4, 3],
},
(response) => {
console.log('response: ', response);
onFecthingImage(response);
},
);
正确的方法是使用 Promise 而不是回调。这是更正后的代码:
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);
});
现在“RTIInputSystemClientremoteTextInputSessionWithID:performInputOperation”错误消失了。