2017-06-15 49 views
0

我一直在努力解決這個問題幾天,我是一名菜鳥,我無法找到解決方案。我正嘗試使用XCode 8.3.3創建用戶註冊和登錄頁面,並將Firebase用作數據庫。無法使用Firebase身份驗證:FIRAuth.auth不起作用

我的代碼如下:

import UIKit 
import Firebase 
import FirebaseAuth 

class SignUpViewController: UIViewController { 

    //Outlets 
    @IBOutlet weak var emailTextField: UITextField! 
    @IBOutlet weak var passwordTextField: UITextField! 

    //Sign Up Action for email 
    @IBAction func createAccountAction(_ sender: AnyObject) { 

     if emailTextField.text == "" { 
      let alertController = UIAlertController(title: "Error", message: "Please enter your email and password", preferredStyle: .alert) 

      let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil) 
      alertController.addAction(defaultAction) 

      present(alertController, animated: true, completion: nil) 
     } else { 
      FIRAuth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in 

      if error == nil { 
       print("You have successfully signed up") 
       //Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username 

       let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home") 
       self.present(vc!, animated: true, completion: nil) 

      } else { 
       let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert) 

       let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil) 
       alertController.addAction(defaultAction) 

       self.present(alertController, animated: true, completion: nil) 
      } 
     } 
    } 
} 

有問題的部分是FIRAuth.auth。該錯誤表示「FIRAuth已重命名爲Auth」,如果我應用了此類修復程序,雖然構建成功,但我只能看到白色屏幕。如果我刪除了代碼,則可以看到之前創建的正常登錄屏幕。

另一件事是當我輸入FirebaseAuth一個紅線出現在建議的單詞列表中劃掉FirebaseAuth,我仍然繼續。

請幫忙。我不知道爲什麼會發生。會不會有任何缺少的pod文件?非常感激。

故事板: storyboard

+0

您是否在AppDelegate中配置Firebase? – PGDev

+0

嘗試移除導入的FirebaseAuth。 – PGDev

+0

將您的窗格更新爲Firebase SDK 4.0 –

回答

4

FIRAuth去年Firebase版本成了Authlink to Docs

import Firebase 

然後,在application:didFinishLaunchingWithOptions:方法,初始化FirebaseApp對象:

// Use Firebase library to configure APIs 
FirebaseApp.configure() 

現在你可以在你的文件中使用(也import Firebase

Auth.auth().createUser(withEmail: email, password: password) { (user, error) in 
    // ... 
} 

希望它可以幫助

+0

我試過了,並建成成功。但我得到了一個白色的屏幕,不是我的初始註冊屏幕 –

+0

@AndrewQin你有沒有rootviewcontroller? –

+0

@AndrewQin在函數func應用程序檢查導航流量 –