ios - 使用 Swift 和 Firebase 更改用户电子邮件和密码

标签 ios swift xcode firebase firebase-authentication

这是我使用 swift 和 firebase 的 iOS 应用程序的编辑按钮。

    var ref = Firebase(url:"https://·············.firebaseio.com")

    @IBAction func Done(sender: AnyObject) {

    ref.changeEmailForUser("users/\(self.ref.authData.uid)/email",
        password: "users/\(self.ref.authData.uid)/provider", toNewEmail: EmailTextField.text)
        { (ErrorType) -> Void in
        if ErrorType != nil {
            print("There was an error processing the request")
        } else {
           print("Email changed successfully")
        }
    }

    ref.changePasswordForUser("users/\(self.ref.authData.uid)/email",
        fromOld: "users/\(self.ref.authData.uid)/provider", toNew: PasswordTextField.text)
        { (ErrorType) -> Void in

        if ErrorType != nil {
          print("There was an error processing the request")
        } else {
            print("Password changed successfully")
        }

    }

ref.childByAppendingPath("users").childByAppendingPath(self.ref.authData.uid).updateChildValues(["name":self.NameTextField.text!,"about":self.TextView.text!,"Picker":self.PickerVar])




}

当用户点击完成按钮时,我想更新他在 firebase 中的所有信息。 电子邮件、密码、姓名等

当我点击完成按钮时,所有信息都更新了,除了电子邮件和密码! 据说处理请求时出错: as the picture here

不知道哪里出错了!我是否以错误的方式使用了 changeEmailForUser 和 changePasswordForUser 函数?

这是 JSON 树:

  {
"users" : {
  "7b595e99-b20d-4961-bcf0-6c46956a0cbe" : {
      "Picker" : "Student",
      "about" : "Hey, I'm Here",
      "email" : "mariah@gmail.com",
      "name" : "Mariah Khayat",
      "provider" : "password"
    },
  "7eb23db6-6b56-4225-9306-22ed0b935b52" : {
      "Picker" : "Teacher",
      "about" : "Hi",
      "email" : "mmm@gmail.com",
      "name" : "Memo",
      "provider" : "password"
   }
  }
   }

最佳答案

根据 Firebase API 造成一些混淆。在我看到 API 之后 https://www.firebase.com/docs/ios/api/#firebase_changeEmailForUserpasswordtoNewEmailwithCompletionBlock有明确的说:

enter image description here

因此对于用户的更新电子邮件,这不是更新配置文件的一部分。因此,您可以按照以下方式更改您的电子邮件地址:

 ref.changeEmailForUser("OldEmailthatYouuserForLogin", password: "correctpassword",
            toNewEmail: "newEmail", withCompletionBlock: { error in
                if error != nil {

                     print("There was an error processing the request")
                    // There was an error processing the request
                } else {

                    print("Email changed successfully")

                    // Email changed successfully
                }
        })

// Dont use edited email for the old email and edited password for the password make sure you are using your actually email and password

关于ios - 使用 Swift 和 Firebase 更改用户电子邮件和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35953867/

相关文章:

android - 在 Android/iOS 浏览器上呈现多个选择选项

ios - 搜索字典数组的简便方法

ios - 快速将字符串格式化为 NSString

c++ - 在.h 中声明名称但在 Xcode 的 .cpp 中报告未声明

ios - 在 iOS 8 中使用 Storyboard 时 FBLoginView 不显示

ios - 如何确定注释是否在 MKPolygonView 内部(iOS)

ios - Swift - 如何在安装之前在应用程序中保存 json 文件

ios - 无法使用 '[APISKeyObjects]' 类型的索引为 'String' 类型的值添加下标吗?

ios - 如何在 plist 中添加预定义值?

ios - swift : Play Video in Landscape Mode When Fullscreen