Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion FirebaseCloudMessagingTutorial.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
Expand Down Expand Up @@ -70,6 +70,9 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0-android'">
<GoogleServicesJson Include="google-services.json" />
<PackageReference Include="Xamarin.GooglePlayServices.Base">
<Version>118.5.0.4</Version>
</PackageReference>
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
Expand Down
21 changes: 18 additions & 3 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}

Expand Down