Failed to get default firebase instance in swift - ios

As I was working on my iOS app, I got this error out of no where
Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'Failed to get default Firebase Database instance. Must call `[FIRApp configure]` (`FirebaseApp.configure()` in Swift) before using Firebase Database.'
on the line initializing DB_BASE
var DB_BASE = Database.database().reference()
class DataService {
static let instance = DataService()
}
I have FirebaseApp.configure() in my didFinishLaunchingWithOptions AppDelegate function, so I'm not sure what the error is all about. I've tried updating pods, restarting my computer, but no luck so far.

I haven't worked with Database specifically, but we use Storage, Analytics and Remote Config. Have you put google-services.json to the root of the project?
The code you provided doesn't make it totally clear, but if DB_BASE by any chance is a member of a singleton (like DataService.instance), try moving it to a different place. Static variables get inited before applicationDidFinishLaunching is called.

Related

Firebase database iOS crashing GTMSessionFetcher

I updated firebase and since then my app keeps crashing with the following error
Fetcher delegate class: NRMAURLSessionTaskDelegate Fetcher made an
extra session: GTMSessionFetcher 0x125d53db0 Couldn't assign
delegate.
Fetcher delegate class: NRMAURLSessionTaskDelegate
-[GTMSessionFetcher setFetcher:forTask:]: unrecognized selector sent to instance 0x125d53db0
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GTMSessionFetcher
setFetcher:forTask:]: unrecognized selector sent to instance
0x125d53db0'
* First throw call stack: (0x18260ad8c 0x1817c45ec 0x182618098 0x1826105c8 0x1824f641c 0x104637b14 0x104613928 0x10461011c
0x102d9364c 0x102d96bdc 0x102d95140 0x102d92a54 0x102db3f90
0x102db36b0 0x102da0e00 0x105bfd1dc 0x105bfd19c 0x105c0bdfc
0x105c006ac 0x105c0bc20 0x105c006ac 0x105c0cd54 0x105c13e38
0x18222fe70 0x18222fb08) libc++abi.dylib: terminating with uncaught
exception of type NSException
the call that I make and crashes is the following:
let reviewsRef = Database.database().reference()
reviewsRef.child("reviews").queryOrdered(byChild: "timestamp").queryLimited(toLast: count)
I added a debug log and the call is made only once.
It seems the line that the app is crashing is
let ref = Database.database().reference()
Did anything changed regarding configuring Firebase from 4.9 to 5.0 version?
Another update:
It seems to be working on the Xcode simulator but not on device. Device is iPhone 6s with 11.4
Kind of working since on simulator I receive the whole database instead of only the "reviews" that I am requesting
if the rules are:
{
"rules": {
".read": true,
but when I change to:
"rules": {
"reviews": {
".read": true,
I get permission denied(on simulator).It has to do maybe with authentication? I understand that those 2 might be two different issues.
I have no idea why this happened on the first place. But I created a new project in firebase with exact same rules and it worked... for some reason the specific project became corrupt on firebase side.
NRMAURLSessionTaskDelegate indicates usage of New Relic - if it worked on a clean project there might be an incompatibility with Firebase

Firebase configuration not working

the Firebase configuration is not working even though it is called in the app delegate method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure();
confic(application: application);
return true
}
I did not had this problem before where my classes were initialised as singletons those particular classes are dependent on Firebase however I decided to instantiate them individually in each view controller instead of using singletons however now I'm getting this issue can anyone help?.
I also tried removing any calls to Firebase from the Appdelegate class and just have FirebaseApp.configure(); included in the delegate however this did not help either.
theconfic(application: application); method contains all my Firebase related calls such as checking if the user has logged in etc.
I moved in here as in previous post I read this may help however it made no difference still getting the same error
Error message
2018-05-16 16:23:42.201080+0100 Jagdschule Gut Grambow[1983:376501] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The default FIRApp instance must be configured before the default FIRAuthinstance can be initialized. One way to ensure that is to call [FIRApp configure]; (FirebaseApp.configure() in Swift) in the App Delegate's application:didFinishLaunchingWithOptions: (application(_:didFinishLaunchingWithOptions:) in Swift).'
* First throw call stack:
(0x1841cad8c 0x1833845ec 0x1841cac6c 0x1021d8244 0x10213b510 0x1021321e8 0x1021209cc 0x102120b5c 0x18e40dedc 0x18e56f628 0x18e56f7a0 0x18e56f360 0x18e23d2c8 0x18e26b4d0 0x102097890 0x102097940 0x18e40dedc 0x18e56f628 0x18e56f360 0x18e23cf24 0x10216b674 0x10216b728 0x18e40dedc 0x18e56f628 0x18e56f360 0x18e40db84 0x18e40e31c 0x18e56f628 0x18e56f7a0 0x18e56f360 0x18e40ced4 0x18e719d88 0x18e17bfd8 0x18dd99254 0x18dd67550 0x18e397a0c 0x18dd66e4c 0x18dd66ce8 0x18dd65b78 0x18e9fb72c 0x18dd65268 0x18e7e09b8 0x18e92eae8 0x18dd64c88 0x18dd64624 0x18dd6165c 0x18dd613ac 0x1869c8470 0x1869d0d6c 0x103aa9220 0x103ab5850 0x1869fc878 0x1869fc51c 0x1869fcab8 0x184173404 0x184172c2c 0x18417079c 0x184090da8 0x186073020 0x18e07178c 0x102130644 0x183b21fc0)
2018-05-16 16:23:42.201344+0100 Jagdschule Gut Grambow[1983:376766] 5.0.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more:
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

NSUncaughtExceptionHandler when using Realm with Crashlytics

I've got Fabric installed in my app, with Crashlytics enabled via a simple Fabric.with([Crashlytics.self]) call in AppDelegate. Everything was working great, until I pulled in Realm. I have a dead-simple function;
class func listObjects() {
let realm = try? Realm()
if let realm = realm {
let objSet = realm.objects(TestObject.self)
print("Retrieved \(objSet.count) objects")
}
}
Calling the function actually works just fine, but I get an odd warning;
[Crashlytics:Crash] Warning: NSUncaughtExceptionHandler is '_ZZ34RLMInstallUncaughtExceptionHandlervEN3$_08__invokeEP11NSException' in '<...>/Frameworks/Realm.framework/Realm'
Has anyone come across this before?
I guess this is happening because Crashlytics checks whether the uncaught exception handler is overridden, because it is relying on that itself, but it is commonly misused for purposes where there would be less dangerous solutions. 🐉
Realm is using this for good reasons: we need to tear down open write transactions. While we are doing that, we still ensure to call the previously configured exception handler as you can see here. So Crashlytics won't loose it's ability to report any exceptions in your app.

Firebase iOS SDK - Missing Database URL

Hi I get the following error that I have inherited from a previous developer. My app keeps crashing with the following :
2016-06-21 22:26:16.828 Drnk[3234:1081556] The default app has not been configured yet.
2016-06-21 22:26:16.832 Drnk[3234:1081556] *** 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:
My App delegate has the following code:
FIRApp.configure()
My controller where I call the database and the app crashes has the following code:
var ref: FIRDatabaseReference!
self.ref = FIRDatabase.database().reference()
I have added the google-services-plist file to my project as instructed.
This all works with another app I am developing but I can't solve this.
Make sure you're not calling FIRDatabase.database().reference() before viewDidLoad
In your class define a var:
var ref: FIRDatabaseReference?
then in viewDidLoad
ref = FIRDatabase.database().reference()
This is how I fixed it here https://stackoverflow.com/a/65866188/4833705
I didn't want to add the same code twice and the comments are kinda long so someone might miss this.
Download and replace the GoogleService-info.plist again since you have already registered the database in your account

Firebase crashes with 'listen() called twice for the same query' error

I was trying to follow the advice and remove the listener when needed and register the listener when needed. So in my UIViewController.viewDidAppear I have the following:
let chatRef = messagesRef.childByAppendingPath(chat.objectId!)
var query = chatRef.queryOrderedByChild("createdAt")
if let since = since {
query = query.queryStartingAtValue(since.timeIntervalSince1970 * 1000)
}
let handle = query.observeEventType(FEventType.ChildAdded, withBlock: completion, withCancelBlock: { (error: NSError!) -> Void in
println("error listening for new Chat messages: \(error)")
});
In my UIViewController.viewWillDisappear() I have
let chatRef = messagesRef.childByAppendingPath(chat.objectId!)
if chatRef != nil {
chatRef.removeAllObservers()
}
But the program crashes every time the ViewController is entered the second time (going to the view controller, navigate away, then come back) with the following error:
*** Assertion failure in -[FPersistentConnection listen:tagId:hashFn:onComplete:], /Users/mtse/Dev/firebase/firebase-client-objc/Firebase/Firebase/Core/FPersistentConnection.m:127
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'listen() called twice for the same query'
The program runs fine if I don't remove the observers and call observeEventType only once in viewDidLoad instead of viewDidAppear.
The program also runs fine even if I remove the observer then add it back if I don't do queryOrderedByChild and queryStartingAtValue.
So what am I doing wrong here?
Disclaimer: I work for Firebase
Listeners in Firebase are specific to the path or query that you register them on. Calling removeAllObservers() removes all observers, but only from that path.
So in your viewWillDisappear() you will need to remove the listeners from the query, instead of the ref.
query.removeAllObservers()
We just made this more explicit in our documentation and are looking at ways to make the API more intuitive.
Update (20150724)
It turns out that calling removeAllObservers() on a FFirebase should remove all observers on queries on that same location too. It will not remove observers at child() locations, but should have worked in your case.
We are investigating what is going wrong, but it seems you have hit a bug in our iOS SDK. Once we find it, we'll release a fixed version. In the meantime the above serves (and will continue to serve) as a valid workaround.

Resources