当用户在注册屏幕上输入新用户名时,userNameTextField
中的文本会根据 Firebase 实时数据库进行检查,以确保用户名尚未被占用。效果很好!
如果您只是在开始输入后删除一两个字母,没问题。但是,如果您在开始输入后删除所有字母,iOS 模拟器就会崩溃。这是代码:
@IBAction func userNameTextFieldEditingChanged(_ sender: Any) {
Auth.auth().signInAnonymously { (user, error) in
if let error = error
{
self.showMessage(messageToDisplay: error.localizedDescription)
return
}
if user != nil {
var databaseReference: DatabaseReference!
databaseReference = Database.database().reference()
Database.database().reference().child("allUsers").child(self.userNameTextField.text!).observeSingleEvent(of: .value, with: {(usernameSnap) in
if usernameSnap.exists(){
self.userNameStatusLabel.text = "Username is already taken."
self.nextButton.isEnabled = false
self.nextButton.alpha = 0.25
} else{
self.userNameStatusLabel.text = ""
}
})
}
}
}
应用程序崩溃后,它会在 Xcode 中向我显示带有消息的 AppDelegate
"Thread 1: signal SIGABRT" after the line "class AppDelegate: UIResponder, UIApplicationDelegate {"
在下面的调试区域中,消息显示为
"libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)"
知道它崩溃的原因以及如何修复它吗?感谢您的帮助!
最佳答案
看起来你得到了
Must be a non-empty string and not contain '.' '#' '$' '[' or ']'
这意味着在您的情况下,您发送的是带有 firebase 的空字符串,这是不可能的。
关于ios - 为什么在检查 Firebase 中是否存在用户名时从 textField 中删除文本时应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54837393/