I just lately applied firebase push notification into my maui app and going through an odd situation,
someday the applying works tremendous and someday it trows exception,saying:
Default FirebaseApp is just not initialized on this course of,Be sure to name FirebaseApp.initializeApp(Context) first
I suppose it’s one thing associated to firebase initialization,
beneath is my code:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.RegisterFirebaseServices()
.UseMauiCommunityToolkit()
personal static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(occasions => {
#if IOS
occasions.AddiOS(iOS => iOS.WillFinishLaunching((_, __) => {
CrossFirebase.Initialize();
FirebaseCloudMessagingImplementation.Initialize();
return false;
}));
#if ANDROID
occasions.AddAndroid(android => android.OnCreate((exercise, _) =>
CrossFirebase.Initialize(exercise)));
#endif
});
return builder;
}
and on button handler, the place exception is being thrown whereas acquiring fcm token
if (CrossFirebaseCloudMessaging.Present != null)
{
await CrossFirebaseCloudMessaging.Present.CheckIfValidAsync();
var token = await CrossFirebaseCloudMessaging.Present.GetTokenAsync();
if (!string.IsNullOrEmpty(token))
{
Preferences.Set("deviceId", token);
}
else
{
return;
}
I’ve adopted these tutorial:
https://maxmannstein.com/index.php/2025/01/19/implementing-firebase-cloud-messaging-in-net-maui-ios/
and