From a5142c338f980a727be58ef8304074ae50d2f3f8 Mon Sep 17 00:00:00 2001 From: Christopher Hofmeister Date: Tue, 1 Apr 2025 09:01:56 -0500 Subject: [PATCH] Issue #1 Error Getting FCM Token Fix: Include Xamarin.GooglePlayservices.Base --- FirebaseCloudMessagingTutorial.csproj | 5 ++++- MainPage.xaml.cs | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/FirebaseCloudMessagingTutorial.csproj b/FirebaseCloudMessagingTutorial.csproj index 65ea7e7..3bf316a 100644 --- a/FirebaseCloudMessagingTutorial.csproj +++ b/FirebaseCloudMessagingTutorial.csproj @@ -1,4 +1,4 @@ - + net9.0-android;net9.0-ios;net9.0-maccatalyst @@ -70,6 +70,9 @@ + + 118.5.0.4 + diff --git a/MainPage.xaml.cs b/MainPage.xaml.cs index 9d55d29..3cef8b1 100644 --- a/MainPage.xaml.cs +++ b/MainPage.xaml.cs @@ -9,13 +9,28 @@ public partial class MainPage : ContentPage public MainPage() { InitializeComponent(); + + CrossFirebaseCloudMessaging.Current.Error += (s, p) => + { + if (p == null) + return; + + Console.WriteLine($"PushNotification.Error, Message = {p.Message}"); + }; } private async void OnCounterClicked(object sender, EventArgs e) { - await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync(); - var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync(); - Console.WriteLine($"FCM token: {token}"); + try + { + await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync(); + var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync(); + Console.WriteLine($"FCM token: {token}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } } }