Plugin.Firebase: Exception - Couldn't retrieve FCM token
I am receiving the error message “Couldn’t retrieve FCM token” while awaiting await CrossFirebaseCloudMessaging.Current.GetTokenAsync();.
Current nuget: Plugin.Firebase.CloudMessaging - 3.0.0
My MauiProgram.cs file is as follows:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureServices()
.ConfigureViews()
.ConfigureViewModels()
.UseMauiCommunityToolkit()
.RegisterFirebaseServices()
.ConfigureEssentials(essentials =>
{
essentials.UseVersionTracking();
})
return builder.Build();
}
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events =>
{
#if IOS
events.AddiOS(iOS => iOS.WillFinishLaunching((_, __) => {
CrossFirebase.Initialize();
return false;
}));
#elif ANDROID
events.AddAndroid(android => android.OnCreate((activity, _) => {
CrossFirebase.Initialize(activity);
}));
#endif
});
builder.Services.AddSingleton(_ => CrossFirebaseCloudMessaging.Current);
return builder;
}
I have the following in my project file:
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
<BundleResource Include="GoogleService-Info.plist" />
</ItemGroup>
Confirmed that the Application ID matches what is listed as the Bundle ID in the GoogleService-Info.plist file.
Am I missing anything else that could be causing this error?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27
@MaxMa04 I figured what the issue was, since our app is a migration from Xamarin to .NET MAUI we had FirebaseAppDelegateProxyEnabled in the info.plist from the xamarin nuget. After removing this from the plist it worked every single time. Maybe it’s worth mentioning in the docs/video for anyone who is still migrating their app.
Thank you for your help!!!
@decv86 Make sure to have all these:
1 - A project in Firebase Cloud for your app; 2 - Your app identifier in the Apple Developer Panel is enabled for push notifications. 3 - A key for your Apple Team with “Apple Push Notifications service (APNs)” enabled. 4 - Upload the key above to your Firebase Cloud app configuration. 5 - Download the JSON in your Project root (not the Platforms folder). 6 - Ensure the file is set up properly in your
csprojfile (you can check the example from this project). 7 - Ensure you have the right config withUIBackgroundModesandCFBundleURLTypesin yourinfo.plist(you can also check the example from this project). 8 - Make sure you have the right config withaps-environmentkey in yourentitlements.plist(check the project with the example). 9 - Last, go to Xcode > Settings > Accounts. Then click on your account on the left and then the button “Download Manual Profiles” to your right. This will update your profiles with the stuff from the Apple Developer System. Make sure to sign your app (either development or distribution) with the same team that you created the keys and other configs above.Following these steps, it should work. If not, repeat each process again and ensure your bundle ID is the same across all configs (Google Firebase Console, Apple Development Panel, your project). If it still doesn’t work, feel free to reach me privately, and we can talk.
I have done a complete video tutorial on YouTube for this plugin, explaining every step you have to make to successfully receive notifications.
You can watch it here: https://youtu.be/EhBI3r1NTsk?si=xVLIf9ca7000Dbzq