2016-07-03 2 views
1

Когда я пытаюсь зарегистрировать нового пользователя, я получаю сообщение об ошибке типа 'FIRDatabaseReference' has no member 'createuser'. См. Изображение ниже.Ошибка при регистрации нового пользователя в Firebase

FIRAuth.auth()?.createUserWithEmail(<email: String>, password: <String>, completion: <FIRAuthResultCallback?(FIRUser?, NSError?) -> Void#>) 

Вот скриншот того, как код выглядит как изображение кода и ImageView:

enter image description here

ответ

0

код не совпадает. ref.createUser отличается от FIRAuth.auth() ?. createUserWithEmail

0

Это рабочий фрагмент кода, который я пробовал несколько дней назад в XCode 7.3.1. Я не знаю, какую версию XCode вы используете. Однако, как вы пробовали, нет предопределенной функции!

func buttonHandleRegister() { 
    guard let email = emailTextField.text, password = passwordTextField.text, name = nameTextField.text else { 
     print("Form is not valid") 
     return 
    } 
    FIRAuth.auth()?.createUserWithEmail(email, password: password, completion: { (user: FIRUser?, error) in 
     if error != nil { 
      print("Error") 
      return 
     } 

     guard let uid = user?.uid else { 
      return 
     } 

     //successfully logged in 


     let ref = FIRDatabase.database().referenceFromURL("https://some-random-name.firebaseio.com/") 
     let usersReference = ref.child("users").child(uid) 

     let values = ["name" : name, "email": email, "password": password] 
     usersReference.updateChildValues(values, withCompletionBlock: { (err, ref) 
      in 

      if err != nil { 
       print(err) 
       return 
      } 

      print("Saved user succesfully") 


     }) 


}) 
} 
1

Попробуйте этот код он работает абсолютно нормально для меня

// 
// ViewController.swift 
// FirebaseExample 
// 
// Created by Belal Khan on 03/10/16. 
// Copyright © 2016 Belal Khan. All rights reserved. 
// 

import UIKit 

//importing firebase 
import Firebase 

class ViewController: UIViewController { 

    //Textfields for email and password 
    @IBOutlet weak var textFieldEmail: UITextField! 
    @IBOutlet weak var textFieldPassword: UITextField! 

    //label for displaying message 
    @IBOutlet weak var labelMessage: UILabel! 

    //button for registration 
    @IBAction func buttonRegister(sender: UIButton) { 
     //do the registration operation here 

     //first take the email and password from the views 
     let email = textFieldEmail.text 
     let password = textFieldPassword.text 

     FIRAuth.auth()?.createUserWithEmail(email!, password: password!, completion: { (user: FIRUser?, error) in 
      if error == nil { 
       self.labelMessage.text = "You are successfully registered" 
      }else{ 
       self.labelMessage.text = "Registration Failed.. Please Try Again" 
      } 

     }) 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     //initialising firebase 
     FIRApp.configure() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

Источник: swift firebase tutorial