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

onMessage and onBackgroundMessage are never called #215

Open
Allyda opened this issue Oct 4, 2022 · 1 comment
Open

onMessage and onBackgroundMessage are never called #215

Allyda opened this issue Oct 4, 2022 · 1 comment

Comments

@Allyda
Copy link

Allyda commented Oct 4, 2022

I am trying to implement push notifications in my ionic project.
It looks like my hooks defined for onMessage and onBackgroundMessage are not working and get never called, even when the phone definitely receives the push notification.

I configured Firebase and Xcode like described and I also receive the test Firebase push notification when my app is closed on my phone. But my registered callback functions are never called.

I receive the push notification also in the native app with the following code:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print(userInfo)
    }

But it is never handed over to ionic. See my code example below:

FirebaseMessaging.requestPermission({forceShow: false}).then(() => {
        FirebaseMessaging.getToken().then(token => {
            console.log('Ionic Device Token: ' + token);
            alert('Device Token: ' + token);

            FirebaseMessaging.onMessage().subscribe((data) => {
                alert('Received notification');
                console.log('Ionic Push Notification Received', JSON.stringify(data));
            });

            FirebaseMessaging.onBackgroundMessage().pipe(tap(data => {
                alert('Received notification');
                console.log('Ionic Push Notification Received', JSON.stringify(data));
            })).subscribe();

            // alternative try:
            cordova.plugins.firebase.messaging.onMessage(function(payload) {
                alert('Received notification');
                console.log("New foreground FCM message: ", payload);
            });
        });

    });
@ragcsalo
Copy link

Same problem for me..... the plugin simply doesn't handle background notifications :-( Will this be ever fixed, or the project is abandoned?

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

2 participants