TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
196 stars 45 forks source link

APNS device token not set before retrieving FCM Token for Sender ID '...'. #202

Open wbhotia-bbl opened 9 months ago

wbhotia-bbl commented 9 months ago

Hi,

iOS push notifications stopped working and I have not been able to resolve it.

FCM Error: APNS device token not set before retrieving FCM Token for Sender ID '...'. Notifications to this FCM Token will not be delivered over APNS. Be sure to re-retrieve the FCM token once the APNS device token is set.

AWS SNS Error: iOS device token must not be more than 400 hexadecimal characters.

I believe the issue is due the FCM Error mentioned above. I have enabled Background Modes but still fails.

info-plist-cap-bm

Found that, AWS SNS does not support FCM v1.0 yet so I disabled FCM v1.0 and still get the same errors.

Has anyone had this issue before and if so please help.

My setup:

MauiProgram.cs

    private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
    {
        builder.ConfigureLifecycleEvents(events =>
        {
#if IOS
            events.AddiOS(iOS => iOS.WillFinishLaunching((_, _) =>
            {
                CrossFirebase.Initialize(CreateCrossFirebaseSettings());
                return false;
            }));
#else
            events.AddAndroid(android => android.OnCreate((activity, _) =>
                CrossFirebase.Initialize(activity, CreateCrossFirebaseSettings())));
#endif
        });

        builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
        return builder;
    }

AppDelegate.cs

public override bool WillFinishLaunching(UIApplication app, NSDictionary options)
{
    var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
    UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
    {
        if (granted && error == null)
        {
            this.InvokeOnMainThread(() =>
            {
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            });
        }
    });

    return base.WillFinishLaunching(app, options);
}

VS Community 2022 v17.7.4 Plugin.Firebase v2.0.5 .NET 6 iOS Target SDK 16.4

TobiasBuchholz commented 7 months ago

Hey and sorry for the late response. Could you please provide a sample project that demonstrates this issue?

khalil2099 commented 5 months ago

my code to initialise FCM is the same as above, i can receive push notification on iOS 15, but not receiving any push notification on iOS 17.

on FCM setting, im using APN Auth Key. I have not tried APN Certificate.

anyone having problem like me ?

LennoxP90 commented 3 weeks ago

I am having the same issue, my client is not generating an fcm token to be used by my server app. My setup is pretty unique I elect to pass the .plist .json information through a socket call from my server so i do not have to hardcode anything in the app (My app is a self contained chat app that different customers use).

The main purpose of this is so that our customers can use their own google firebase account

Keep in mind all of this worked fine in Xamarin with the legacy libraries. Same firebase account and config files.

CrossFirebase.Initialize( null,
                          new Firebase.Core.Options( saved_request.AppId,
                                                     saved_request.ProjectNumber )
                          {
                            ProjectId = saved_request.ProjectId,
                            ApiKey = saved_request.ApiKey,
                            BundleId = "<hard-coded-value>",
                            StorageBucket = saved_request.StorageBucket
                          } );
FirebaseCloudMessagingImplementation.Initialize();

var token = await Firebase.CloudMessaging.Messaging.SharedInstance.RetrieveFcmTokenAsync( saved_request.ProjectNumber );

the retrieve token fails with Error Domain=com.google.fcm Code=505 "No APNS token specified before fetching FCM Token"