firebase
firebase copied to clipboard
[IOS] The default FirebaseApp instance must be configured before the default Authinstance can be initialized
Hi @NathanWalker
When I call firebase().auth().addAuthStateChangeListener that will throw error
NativeScript encountered a fatal error: Uncaught Error: The default FirebaseApp instance must be configured before the default Authinstance can be initialized. One way to ensure this is to call `FirebaseApp.configure()` in the App Delegate's `
application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI).
at
get native(file: app/webpack:/--/node_modules/@nativescript/firebase-auth/index.ios.js:1237:0)
at addAuthStateChangeListener(file: app/webpack:/--/node_modules/@nativescript/firebase-auth/index.ios.js:907:0)
to prevent this error I should declare init on a delegate applicationDidFinishLaunchingWithOptions then it work !
Do you have an idea what happen
Thanks
You need to call the following before using the other packages
import { firebase } from '@nativescript/firebase-core'
firebase().initializeApp();
I did that but the same result, the only work around that i've found is like I read in the Firebase docs that we should initialize firebase on a delegate
import { firebase } from '@nativescript/firebase-core'
if(isAndroid)
{
firebase().initializeApp();
}
import '@nativescript/firebase-auth'; // only needs to be imported 1x
import '@nativescript/firebase-messaging';
if (global.isIOS) {
@NativeClass()
@ObjCClass(UIApplicationDelegate)
class UIApplicationDelegateImpl extends UIResponder implements UIApplicationDelegate {
applicationContinueUserActivityRestorationHandler(application: UIApplication, userActivity: NSUserActivity, restorationHandler: (p1: NSArray<UIUserActivityRestoring>) => void): boolean {
return handleContinueUserActivity(userActivity);
}
applicationOpenURLOptions(app: UIApplication, url: NSURL, options: NSDictionary<string, any>): boolean {
return handleOpenURL(url);
}
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary<string, any>): boolean {
firebase()
.initializeApp()
.then((app) => {
//firebase().crashlytics().setCrashlyticsCollectionEnabled(true);
firebase().messaging().showNotificationsWhenInForeground = true;
console.error(firebase().messaging().isDeviceRegisteredForRemoteMessages)
console.error(firebase().messaging().isDeviceRegisteredForRemoteMessages)
});
return true
}
}
Application.ios.delegate = UIApplicationDelegateImpl;
}
@kefahB is it possible to show me your use case? . Curious where the next firebase call is.
Hi @triniwiz,
I've investigated the code .. the init doesn't initialize at all please see here
I didn't understand why did you put a function inside the push ? it is for some async/await stuff ?
Once you remove the function firebase init get called.
If there is no sharedApplication usually the case when initializeApp is called early in the project the initialize method is added to a queue to be called when the app triggers the launch event then it will trigger the events on our end
I've declared the init at the begin of the app.ts .. it doesn't work, neither put it in a async function!