ios - 尝试为多个 View Controller 设置 Firebase 身份验证时出错

标签 ios swift xcode firebase firebase-authentication

我正在尝试为用户创建一个 Firebase Auth 方法来创建一个帐户。但是,我有多个 View Controller ,要求我在处理 Firebase Auth 'createUser' 函数之前保存用户信息。所以我为此创建了一本字典。我也在使用 Swift。

这就是我说我有多个创建帐户 View Controller 时的意思。

enter image description here

然后,我在 App Delegate 中添加了一个字典,用于在激活 Firebase 的“createUser”方法之前保存用户信息。

 // Instance of AppDelegate
static let shared: AppDelegate = UIApplication.shared.delegate as! AppDelegate
// Dictionary for user information
var userInformation: Dictionary<String, Any> = [:]

这是“输入您的电子邮件地址” View Controller 的代码。

 // After Email is entered, next button is tapped to take user to second step of sign up process
@IBAction func nextButtonTapped(_ sender: UIButton) {
    AppDelegate.shared.userInformation ["createEmail"] = emailTextField.text

最后是“名称和密码” View Controller 。这也是我希望从最后一个 View Controller 保存的电子邮件到位的地方。我尝试调用存储在字典中的所有已保存信息,以便我可以实现 Firebase Auth.auth().createUser 方法。

IBAction func nextButtonTapped(_ sender: UIButton) {
    AppDelegate.shared.userInformation["name"] = nameTextField.text
    AppDelegate.shared.userInformation["password"] = createPassWordTextField.text

    let createEmail = AppDelegate.shared.userInformation["createEmail."]
    let name = AppDelegate.shared.userInformation["name"]
    let password = AppDelegate.shared.userInformation["password"]

    Auth.auth().createUser(withEmail: createEmail, password: password ) { (user, error) in
        if error == nil && user != nil {
            print("User Created!")
            // If user is created go to Welcome Page
            self.performSegue(withIdentifier: "goToWelcomeVC", sender: self)
        } else {
            print("error creating User")

之后我想创建用户的帐户。然后他们将被带到欢迎页面,然后是主页。但是我似乎收到了这个错误。我是不是碰巧查错了字典?对于我的登录 View Controller ,它非常简单。如下所示。

 //Login Button

@IBAction func loginButtonTapped(_ sender: UIButton) {
  // Signing in User with Email and Password using Firebase
    if let email = emailTextField.text, let password = passwordTextField.text {

        Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
            // check if user isnt nil
            if user != nil {
                print("Login Successful")
                // user is found, go to home screen
                self.performSegue(withIdentifier: "goToHomeVC", sender: self)
            } else {
                print("loginError")

我尝试通过让电子邮件、密码和名称 = UITextField.text 对注册 View Controller 执行相同的操作。有人可以帮我解决我在这里做错了什么吗?

编辑* 这是我收到的错误。 enter image description here

谢谢。

最佳答案

我不知道这是否能解决您的问题,但是 let createEmail = AppDelegate.shared.userInformation["createEmail."] 正如您在此处看到的那样,您的 key 与第一个不同,您将信息保存为 ["createEmail"]最后没有点。

关于ios - 尝试为多个 View Controller 设置 Firebase 身份验证时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52215816/

相关文章:

Xcode:如何从项目继承目标设置

iOS 在代码中获取对 Interface Builder 中添加的特定自动布局约束的引用

ios - Swift iOS -storyboard.instantiateViewController(withIdentifier :) causing retain cycle

ios - 如何搜索目录的目录?

ios - CLLocation Manager 检查 requestAlwaysAuthorization,如果不接受则退出应用程序

ios - 如何在 iOS 6 中强制 UIViewController 为纵向

ios - 平衡ios电池生命周期和定位精度

iphone - 我需要 UINavigationController 吗?

swift - 类类型属性不应该有 static 关键字吗?

iphone - 如何避免从照片库中选择或从 ios 中的相机捕获的图像的背景?