2017-02-12 410 views
0

我是編碼新手,所以我很抱歉如果對此的回答很明顯。將[FIRApp configure]添加到您的應用程序初始化錯誤

我試着將我的應用程序同步到Firebase服務器,我已經安裝了cocoapods,添加了GoogleService信息plist。然而,當我嘗試創建一個新的用戶,我得到的錯誤:

The default Firebase app has not yet been configured. Add [FIRApp configure] to your application initialization

應用委託我使用

import UIKit 
import Firebase 


@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> ObjCBool { 

     FIRApp.configure() 

     return true 
    } 

代碼上申請用戶

import UIKit 
import Firebase 
import FirebaseAuth 

class signUpViewController: UIViewController { 



    @IBOutlet var fullNameTextField: UITextField? 
    @IBOutlet var contactNumberTextField: UITextField? 
    @IBOutlet var emailTextField: UITextField? 
    @IBOutlet var passwordTextField: UITextField? 
    @IBOutlet var dateOfBirth: UIDatePicker? 


    func createMyAlert(title: String, message: String) { 

     let alarm = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) 
     alarm.addAction(UIAlertAction(title: "ok", style: .default, handler: { (ACTION) -> Void 
      in self.dismiss(animated: true, completion: nil) 

     })) 

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

    @IBAction func continueButtonPressed(_ sender: Any) { 

     if fullNameTextField?.text == "" || contactNumberTextField?.text == "" || emailTextField?.text == "" || passwordTextField?.text == "" { 

      createMyAlert(title: "Error", message: "Please complete all fieds") 

     } else { 

     // This will create a new user 
      FIRAuth.auth()?.createUser(withEmail: (self.emailTextField?.text!)!, password: (self.passwordTextField?.text!)!) { (user, error) in 


     // this code will check the user isnt nil 

       if let u = user { 

        self.performSegue(withIdentifier: "createProfile", sender: self) 

       } 
       else 
       { 

        self.createMyAlert(title: "Oops", message: "Error") 

       } 
      } 

     } 
    } 

} 
+0

歡迎堆棧溢出,而不是配置在

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> ObjCBool { 

嘗試覆蓋在臨init方法和cconfigure fireapp如下的。我嘗試過格式化代碼沒有成功,請花些時間讓代碼儘可能清晰。 – GabrielOshiro

回答

0

貌似調用FIRApp.configure()在您實際嘗試訪問數據庫之前未得到執行。

override init() { 
super.init() 
FIRApp.configure() 
// not really needed unless you really need it  FIRDatabase.database().persistenceEnabled = true 
} 

檢查下面的鏈接瞭解更多細節:

The default app has not been configured yet