I am using Plugin.Firebase
and Plugin.Firebase.Crashlytics
packages for implementing push notification in my MAUI application. I referred this blog and it was working fine on the Android platform.
Now I am working on the push notification tapping on Android platform and I am referring this blog by the same person. On this blog they are suggested to register the NotificationTapped
event on MauiProgram.cs
. Below is the code for that:
CrossFirebaseCloudMessaging.Current.NotificationTapped += (sender, e) =>
{
System.Diagnostics.Debug.WriteLine("Tapped");
};
I have added it on MauiProgram.cs
and pushed a test notification. But when I tap on the notification this event is not firing.
Below is my complete MauiProgram.cs
codes:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
CrossFirebaseCloudMessaging.Current.NotificationTapped += (sender, e) =>
{
System.Diagnostics.Debug.WriteLine("Tapped");
};
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiRGPopup()
.RegisterFirebaseServices()
.UseMauiCommunityToolkit()
.UseUserDialogs(true, () =>
{
#if ANDROID
var fontFamily = "OpenSans-Regular.ttf";
#else
var fontFamily = "OpenSans-Regular";
#endif
AlertConfig.DefaultMessageFontFamily = fontFamily;
AlertConfig.DefaultUserInterfaceStyle = UserInterfaceStyle.Dark;
AlertConfig.DefaultPositiveButtonTextColor = Colors.Purple;
ConfirmConfig.DefaultMessageFontFamily = fontFamily;
ActionSheetConfig.DefaultMessageFontFamily = fontFamily;
ToastConfig.DefaultMessageFontFamily = fontFamily;
SnackbarConfig.DefaultMessageFontFamily = fontFamily;
HudDialogConfig.DefaultMessageFontFamily = fontFamily;
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.UseFFImageLoading()
.UseMauiCompatibility()
.ConfigureMauiHandlers(handlers =>
{
#if __ANDROID__
//Handler section
#elif IOS
//Handler section
#endif
});
return builder.Build();
}
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events => {
#if IOS
events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => {
CrossFirebase.Initialize(CreateCrossFirebaseSettings());
CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
return false;
}));
#else
events.AddAndroid(android => android.OnCreate((activity, _) =>
CrossFirebase.Initialize(activity, CreateCrossFirebaseSettings())));
CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
#endif
});
builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
return builder;
}
private static CrossFirebaseSettings CreateCrossFirebaseSettings()
{
return new CrossFirebaseSettings(
isAuthEnabled: true,
isCloudMessagingEnabled: true,
isAnalyticsEnabled: true);
}
}
I have added it on the CreateMauiApp()
function like above. Is that the exact place for adding it? I didn't find anything on the MauiProgram.cs
when I check the demo project from that blog.
Is this tapping is enough for all the 3 modes? I mean background mode
, foreground mode
and killed mode
?