firebase Push notification crashing on MAUI IOS
I recently migrated my live Xamarin.Forms iOS app to .NET MAUI and implemented Firebase push notifications using plugin.firebase.cloudmessaging in the MAUI version of the app.
Everything is working fine on Android and iOS in terms of receiving and displaying push notifications. However, I've noticed a strange issue:
On iOS, the app sometimes crashes unexpectedly.
The crash seems to happen intermittently when the user taps the login button on the login screen.
This doesn't happen consistently and isn't affecting all users.
I have two suspicions about what might be causing this:
App Migration and Cache: Could this issue be caused by users updating the app from the App Store where the older version was built with Xamarin, and the new version is built with .NET MAUI? Is it possible that some cached data from the old version is causing the crash in the new MAUI-based version?
Firebase iOS Integration: Could there be something wrong or incomplete with the Firebase push notification integration on iOS specifically?
Has anyone faced a similar issue after migrating to .NET MAUI, especially related to Firebase push notifications or caching after an upgrade from Xamarin?
Here is my implementation ,
on maui program.cs
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events => {
#if IOS
events.AddiOS(iOS => iOS.WillFinishLaunching((_, __) => {
CrossFirebase.Initialize();
FirebaseCloudMessagingImplementation.Initialize();
return false;
}));
#if ANDROID
events.AddAndroid(android => android.OnCreate((activity, _) =>
CrossFirebase.Initialize(activity)));
#endif
});
return builder;
}`
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.RegisterFirebaseServices()
.UseMauiCommunityToolkit()
and on login button handler:
if (CrossFirebaseCloudMessaging.Current != null)
{
await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
if (!string.IsNullOrEmpty(token))
{
Preferences.Set("deviceId", token);
}
else
{
return;
}
this is stange that it is working some time and for some user it is crashing on ios