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

onMessageReceived() can't receive Notification in background when app is closed #426

Closed
dhruvika123 opened this issue Jun 11, 2020 · 1 comment
Labels
ignored issue template The reported ignored the issue template so required information may not be present support Support is being requested but not a necessarily a bug

Comments

@dhruvika123
Copy link

dhruvika123 commented Jun 11, 2020

Hello,
I'm not able to receive any notification in background as system notification in Android and IOS

Ionic CLI : 5.4.4
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
@angular/cli : 8.1.3

Dependencies in package.json for Firebase X plugins:
"dependencies": {
"@ionic-native/firebase-x": "^5.26.0",
"cordova-plugin-firebasex": "^9.1.2-cli",
}

Code of FCM service for notification.

async listenToNotifications() {

return this.firebaseNative.onMessageReceived().subscribe(
 async res => {
    this.translate.get("OK").subscribe(value => {
      this.ok_label = value;
    });
    this.translate.get("CANCEL").subscribe(value => {
      this.cancel_label = value;
    });
    let msg: any = res;
    if (this.platform.is("android")) {
      if (msg.type == "publish_ig") {
        msg.body = msg.postText;
        let alert = await this.alertCtrl.create({
          header: msg.title,
          message: msg.titleText,
          buttons: [
            {
              text: this.cancel_label,
              role: "cancel"
            },
            {
              text: this.ok_label,
              handler: async () => {
                let modal =await this.modalCtrl.create({
                  component:ShareInstagramPage,
                  componentProps:	msg
                });
                modal.present();
              }
            }
          ]
        });
        alert.present();
      }
    } else {

      if (
        msg["gcm.notification.type"] == "publish_ig" &&
        msg.tap
      ) {
        let data = {
          type: msg["gcm.notification.type"],
          titleText: msg["gcm.notification.titleText"],
          origin: msg["gcm.notification.origin"],
          blogId: msg["gcm.notification.blogId"],
          body: msg["gcm.notification.notificationText"],
          igPic: msg["gcm.notification.igPic"],
          screenName: msg["gcm.notification.screenName"],
          media0: msg["gcm.notification.media0"],
          media1: msg["gcm.notification.media1"],
          media2: msg["gcm.notification.media2"],
          media3: msg["gcm.notification.media3"]
        };
        
        let modal =await this.modalCtrl.create({
          component:ShareInstagramPage,
          componentProps:	msg
        });
        modal.present();
      }
    }
  })

}

And this method listenToNotifications() is calling in app.component.ts when platform is ready.

Currently when i am sending notification via backend I'm receiving notification alert but only when app is open.

Really appreciate if anyone can help.
Thanks

@dpa99c
Copy link
Owner

dpa99c commented Jun 11, 2020

Background notifications are working fine for myself and other users of this plugin, indicating the issue is not caused by a bug in the plugin code.

Please use the example project as a known working codebase to validate your Firebase configuration.

Please also search for existing closed issues which may help you eg #425

@dpa99c dpa99c closed this as completed Jun 11, 2020
@dpa99c dpa99c added ignored issue template The reported ignored the issue template so required information may not be present support Support is being requested but not a necessarily a bug labels Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignored issue template The reported ignored the issue template so required information may not be present support Support is being requested but not a necessarily a bug
Projects
None yet
Development

No branches or pull requests

2 participants