Native FCM plugin, background notifications

We are using ionic native FCM plugin which in background is using https://github.com/fechanique/cordova-plugin-fcm

We do nothing special, simple code like docs described:

fcm.subscribeToTopic('abcdef');

fcm.getToken().then(token=>{
    console.log('FCM token:', token);
});

fcm.onNotification().subscribe(data=>{
    console.log('onNotification, data:', data);

    if(data.wasTapped){
        console.log('Received in background');
    } else {
        console.log('Received in foreground');
    };
})

fcm.onTokenRefresh().subscribe(token=>{
    console.log('FCM refresh token:', token);
})

fcm.unsubscribeFromTopic('abcdef);

the problem is if we run the app in background, also not closed but only in background, the Notification is appearing in the notifications try and if we tapped on it the app is opening but the onNotification event is not fired and so also data.wasTapped is never true.

So the implementation is working well for foreground notifications but not so good for background notifications.

So perhaps we are misunderstanding somthing?

3 Likes

Same issue here, when receiving the notification with app in foreground it logs correctly and I can see the wasTapped = false, but when the app is in background the notification is in the tray but event doesn’t fire at all.

The problem seems to be solved if you add the following in the payload’s notification object:
"click_action":"FCM_PLUGIN_ACTIVITY"

6 Likes

Can you post your notification payload?

I had the same problem, but I found out that my test payload was sending only data. It worked after I updated my test payload as follows:

let payload = {
    notification: {
        title: 'Test title',
        body: 'Test body',
    },
    data: {someKey: 'someValue'}
};

Thank You Very Much !!. This worked for me !

Thank You. So many solution, and this was the reason.

Sir can u plz tell me in which section we have put above code?