Firebase built-in push notification plugin not working

I tried using the Firebase native plugin to send push notifications. But it does not work (not receiving a message to a real device). Can you tell me how to do this?

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 completing the above implementation, I tried to send a push notification using User Segmentthe firebase compose console.

+4
source share
1 answer

There may be various reasons why push notifications do not work. I have provided a set of steps for implementing push notifications. Look, maybe you missed something.

push- Ionic ( android):

. Firebase package name id config.xml.

  1. google-services.json .
  2. Android $ ionic platform add android ( )
  3. firebase $ ionic plugin add cordova-plugin-firebase.

. , google-services.json , .

  1. firebase onNotificationOpen.

  2. build.gradle :

    buildscript {
    // ...
        dependencies {
            // ...
            classpath 'com.google.gms:google-services:3.1.0'
        }
    }
    
    //....
    
    dependencies {
        // SUB-PROJECT DEPENDENCIES START
        // ...
        compile "com.google.firebase:firebase-core:+"
        compile "com.google.firebase:firebase-messaging:+"
    }
    
  3. Android $ ionic build android

  4. push-. .

. API - , Cloud Messaging Legacy server key firebase. , , , subscribe.

+6

Source: https://habr.com/ru/post/1678056/


All Articles