如何使用 firebase 选项卡式事件导航到页面

[ad_1]

你好,
我正在尝试导航到 firebase 通知 tabb 事件的特定页面,除了导航到特定页面之外,一切都运行正常,事件正在触发但未导航,我该如何修复它。 会深深感激。
问候,

我尝试过的:

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);
    }

}

解决方案1

朋友你好!

在文件 App.xaml.cs 中,在 InitializeComponent() 之后设置操作:

CrossFirebaseCloudMessaging.Current.NotificationTapped += Current_NotificationTapped;

然后创建函数:

私有无效 Current_NotificationTapped(对象发送者,FCMNotificationTappedEventArgs e)
{
尝试
{
var data = e.Notification.Data;
MainPage = new DetailsPage();

}
catch(异常前)
{
System.Diagnostics.Debug.WriteLine(“异常:>>” + ex);
}
}

[ad_2]

コメント

标题和URL已复制