TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception - Couldn't retrieve FCM token

wynston-champion-actabl opened this issue · comments

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?

Try adding line: FirebaseCloudMessagingImplementation.Initialize(); after CrossFirebase.Initialize(); in IOS section.

I have a similar issue.....without this line FirebaseCloudMessagingImplementation.Initialize() the app runs but the GetTokenAsync() throws NULL reference exception.

however, If I add the line then the app crashes with NULL reference exception in FirebaseCloudMessagingImplementation.RegisterForRemoteNotifications()

don't know what to do.

I got Android to work but I cannot get iOS to work.

I'm facing this issue for iOS.
I'm using

Do we have any updates on this issue? My project is equal to the one described, and I've also followed the instructions (including adding FirebaseCloudMessagingImplementation.Initialize()) but still when I run:

await CrossFirebaseCloudMessaging.Current.GetTokenAsync();

It throws the exception that "Couldn't retrieve FCM token". I did check in the project's source code when this exception is thrown but basically is if the SharedInstance token is empty. I was not sure where that come from.

It works for me, so check if the FCM configuration is correct. I had such problems when the admin did not add the APN token in the Firebase console. Also verify that all BundleIds etc. are the same everywhere.

commented

Hi! Help pls!!! Has anyone who had the error managed to solve it?

For me, I had all the right certificates and keys uploaded to Google Cloud, but still didn’t work; but I think I had created those keys after importing my development and distribution certificates. So I suggest you to open XCode and update your profile and try again. After I did that, it started working.

commented

For me, I had all the right certificates and keys uploaded to Google Cloud, but still didn’t work; but I think I had created those keys after importing my development and distribution certificates. So I suggest you to open XCode and update your profile and try again. After I did that, it started working.

Hi @chaoserene , thanks for the answer, but what does it mean - update your profile? I have released new profiles AppStore, Developer, AddHoc - nothing helps... I thought maybe it doesn't work in debug mode, in the end it didn't work either... it's just killing me...

@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 csproj file (you can check the example from this project).
7 - Ensure you have the right config with UIBackgroundModes and CFBundleURLTypes in your info.plist (you can also check the example from this project).
8 - Make sure you have the right config with aps-environment key in your entitlements.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.

commented

@chaoserene How can I write to you? I need help.

@decv86 You can reach me per email that's on my profile.

@decv86 Were you able to fix this? I'm wondering what was the final solution for you

commented

@decv86 Were you able to fix this? I'm wondering what was the final solution for you

I remove FirebaseAppDelegateProxyEnabled parameter in the iOS configuration.