Bagaimana cara menavigasi ke halaman menggunakan acara tab firebase

pemrograman

[ad_1]

Hai,
Saya mencoba menavigasi ke halaman tertentu pada acara tabb notifikasi firebase, semuanya berjalan dengan baik kecuali menavigasi ke halaman tertentu, acara terpicu tetapi tidak bernavigasi, bagaimana cara memperbaikinya. akan sangat menghargai.
Salam,

Apa yang saya coba:

C#
using Microsoft.Maui.LifecycleEvents;
using Plugin.Firebase.Auth;
using Plugin.Firebase.Bundled.Shared;
using Plugin.Firebase.Crashlytics;
using CommunityToolkit.Maui;
using CommunityToolkit.Maui.Storage;
using Plugin.Firebase.CloudMessaging;
#if IOS
using Plugin.Firebase.Bundled.Platforms.iOS;
#else
using Plugin.Firebase.Bundled.Platforms.Android;
#endif
using Microsoft.Extensions.Logging;
//using Plugin.MauiMTAdmob;

namespace LatestMobilePrices;

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
            .UseMauiCommunityToolkit()
                        .RegisterFirebaseServices()
                        //.UseMauiMTAdmob()
            .ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
				fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
			});

#if DEBUG
		builder.Logging.AddDebug();
#endif
        builder.Services.AddSingleton<IFileSaver>(FileSaver.Default);
        builder.Services.AddTransient<savepage>();

        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);
                CrossFirebaseCloudMessaging.Current.NotificationTapped+=(sender,e)=>
                {
                System.Diagnostics.Debug.WriteLine("tabbed");

                    Shell.Current.GoToAsync(nameof(savepage));
                };
#endif
        });

        builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
        return builder;
    }

    private static CrossFirebaseSettings CreateCrossFirebaseSettings()
    {
        return new CrossFirebaseSettings(
            isAuthEnabled: true,
            isCloudMessagingEnabled: true,
            isAnalyticsEnabled: true);
    }

}

Solusi 1

Hai teman!

Di file Anda App.xaml.cs, setelah InitializeComponent() atur tindakan:

CrossFirebaseCloudMessaging.Current.NotificationTapped += Current_NotificationTapped;

Dan kemudian buat fungsinya:

private void Current_NotificationTapped (pengirim objek, FCMNotificationTappedEventArgs e)
{
mencoba
{
var data = e.Pemberitahuan.Data;
Halaman Utama = Halaman Detail baru();

}
menangkap (Pengecualian ex)
{
System.Diagnostics.Debug.WriteLine(“Pengecualian:>>” + ex);
}
}

[ad_2]

コメント

タイトルとURLをコピーしました