The default app has not been configured yet

后端 未结 9 1538
予麋鹿
予麋鹿 2020-12-02 19:59

I\'m trying to upgrade my app to the new version of Firebase. I went through the setup guide and edited all of my code to match the new syntax. However, when I run the app,

相关标签:
9条回答
  • 2020-12-02 20:55

    In AppDelegate.m, outside of didFinishLaunchingWithOptions,

    override init() {
       FIRApp.configure()
       FIRDatabase.database().persistenceEnabled = true
    }
    
    0 讨论(0)
  • 2020-12-02 20:55

    iOS 9.2
    Swift 2.1.1
    Xcode 7.2.1
    Mac OSX 10.10.5

    Same error here using the following code:

    AppDelegate.swift:

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
    
        func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
            // Override point for customization after application launch.
    
            FIRApp.configure()
    
    
            return true
        }
    

    ViewController.swift:

    import UIKit
    import Firebase
    
    class ViewController: UIViewController {
    
    
        var db = FIRDatabase.database().reference()
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
    
            //Create some data in Firebase db:
            db.child("key").child("subkey").setValue("hello world")
    
        }
    

    I also added the file GoogleService-Info.plist to my project directory as described in the Firebase Getting Started Guide.

    And I made my Firebase db public with the following Rules:

    {
      "rules": {
        ".read": true,
        ".write": true
      }
    }
    

    Making the following changes to ViewController.swift is what worked for me:

    class ViewController: UIViewController {
    
    
        var db: FIRDatabaseReference!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
    
            db = FIRDatabase.database().reference()
            db.child("key").child("subkey").setValue("hello world")
    
        }
    

    Prior to running my app, my Firebase db looked like this:

    myiosdata-abc123: null
    

    After running my app, my Firebase db looked like this:

    myiosdata-abc123
    - key
       |
       +--- subkey: “hello world”
    
    0 讨论(0)
  • 2020-12-02 20:55

    Swift 5 - Easy Solution

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    return true
    }
    
    
    //MARK:- This function will auto run and firebase will configure successfully
    override init() {
        super.init()
            FirebaseApp.configure()
            // not really needed unless you really need it 
            FIRDatabase.database().persistenceEnabled = true
    }
    

    Happy Coding

    0 讨论(0)
提交回复
热议问题