Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception - Couldn't retrieve FCM token #335

Open
wynston-champion-actabl opened this issue Aug 19, 2024 · 3 comments
Open

Exception - Couldn't retrieve FCM token #335

wynston-champion-actabl opened this issue Aug 19, 2024 · 3 comments

Comments

@wynston-champion-actabl
Copy link

wynston-champion-actabl commented Aug 19, 2024

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?

@wynston-champion-actabl wynston-champion-actabl changed the title Couldn't retrieve FCM token Exception - Couldn't retrieve FCM token Aug 19, 2024
@AndrzejKozik
Copy link

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

@luisrr1590
Copy link

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.

@brian-smith723
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants