Firebase native plugin with push notifications is not working


#1

Hi,

I have tried to use Firebase native plugin to send push notifications.But it is not working.Can you tell me how to do that?

I’m creating Ionic 3 Apps.

url: https://ionicframework.com/docs/native/firebase/

app.component.ts


constructor(platform: Platform, private firebase: Firebase) {

    platform.ready().then(() => {
        this.firebase.getToken()
            .then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
            .catch(error => console.error('Error getting token', error));

 this.firebase.onNotificationOpen()
            .subscribe(res => {
                if (res.tap) {
                    // background mode
                    console.log("background");
                    console.log(res);
                    alert(res);
                } else if (!res.tap) {
                    // foreground mode
                    console.log("foreground");
                    console.log(res);
                    alert(res);
                }
            });

      });
}

After the above implementation, I have tried to send push notification using User Segment on firebase compose message console.But no luck.Do I need to add more code to work this functionality? Please let me know.Thanks.


#2

Do you get a token for the device?


#3

Hi Sujan12,

Actually, I cannot test this on Emulator due to issue on my laptop’s hardware.Hence I directly test this on the real device.I have used User Segment option on firebase console when I was sending the notifications.I don’t need to send it device wise yet.Do you think why this is not working? Thanks.


#4

I have implemented Analytics functionality using this native plugin and it is working fine.An issue is only with the push notifications.


#5

This doesn’t matter - you can also look at the console on your device:

Follow these instructions here to debug the problem in Chrome dev tools: https://ionic.zone/debug/remote-debug-your-app#android Look at the console and network tabs for errors.


#6

Thank you so much for the debugging option.I have configured it and working fine.
Yes, I can see the token id has been generated.I have sent the message specifically for that id.But still, I can not see the message.What are your thoughts here?


#7

What happens if the app is in background? Does the OS display the notification?

If not, something is wrong with the delivery to your device.
If yes, something is wrong with the code to handle/show notifications.


#8

Thank you, sir.You promoted me as a real Ionic app developer by mentioning the really awesome debugging option.My idea was to purchase a new laptop due to the hardware issue on current one. You saved that money too :slight_smile:

My issue was The package name on config.xml file and the firebase console app are different.I have created a new app using config.xml name and now it is working. Have a nice day ahead friend :slight_smile:

This also will help for someone have the same kind of issue: Stackoverflow