Please help. After migrating to new Firebase I can't retrieve data. Use this construction:
let ref = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
ref.observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) in
let postDict = snapshot.value as! [String : AnyObject]
print("\(postDict)")
})
}
After running I see error:
2016-05-19 10:04:22.264 123a[88652:13688922] The default app has not been configured yet.
2016-05-19 10:04:22.276 123a[88652:13688922] *** Terminating app due to uncaught exception 'MissingDatabaseURL', reason: 'Failed to get FIRDatabase instance: FIRApp object has no databaseURL in its FirebaseOptions object.'
*** First throw call stack:
I read documentation, but can't resolve this problem. GoogleService-Info.plist I add to project.
So, with mine, I also had a ref being declared immediately when the view controller was instantiated. I had to make it load after the app had been configured in the app delegate with
FIRApp.configure()
.Before:
After:
This delays the instantiation of the database reference until its needed, which wont be until
viewDidLoad
on your initial view controller.I was getting this error until I made
FIRApp.configure()
the first line in theAppDelegate
didFinishLaunchingWithOptions
Make sure you have downloaded the
GoogleService-Info.plist
file from your Firebase console and added to the root of your project directory.Once you have added it call this function from
didFinishLaunchingWithOptions
in AppDelegate:Thats it, it should be up and running!