#if IOS
using Plugin.Firebase.iOS;
#else
using Plugin.Firebase.Android;
#endif
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
return MauiApp
.CreateBuilder()
.UseMauiApp<App>()
...
.RegisterFirebaseServices()
.Build();
}
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events => {
#if IOS
events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => {
CrossFirebase.Initialize(app, launchOptions, CreateCrossFirebaseSettings());
return false;
}));
#else
events.AddAndroid(android => android.OnCreate((activity, state) =>
CrossFirebase.Initialize(activity, state, CreateCrossFirebaseSettings())));
#endif
});
builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
return builder;
}
private static CrossFirebaseSettings CreateCrossFirebaseSettings()
{
return new CrossFirebaseSettings(isAuthEnabled: true);
}
} |