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

Push Notifications not received when app is in background #851

Open
5 tasks done
hal-berto opened this issue Dec 11, 2023 · 3 comments
Open
5 tasks done

Push Notifications not received when app is in background #851

hal-berto opened this issue Dec 11, 2023 · 3 comments
Labels
Cloud Messaging Related to Firebase FCM / Push Notifications / APNS ios relates to iOS platform runtime issue An issue related to app runtime

Comments

@hal-berto
Copy link

Bug report

CHECKLIST

  • I have reproduced the issue using the example project or provided the necessary information to reproduce the issue.
  • I have checked that no similar issues (open or closed) already exist.

Current behavior:

Notification messages are received only when app is in foreground. If the app is in background or is closed, notifications are no more received.

Expected behavior:

Notifications should be received even if the app is in background or is closed

Environment information

  • Cordova CLI version
    • 11.0.0
  • Cordova platform version
    • android 12.0.1
  • Plugins & versions installed in project (including this plugin)
    cordova-plugin-advanced-http 3.3.1 "Advanced HTTP plugin"
    cordova-plugin-device 2.1.0 "Device"
    cordova-plugin-file 7.0.0 "File"
    cordova-plugin-firebasex 16.2.0 "Google Firebase Plugin"
    cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
    cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-x-socialsharing 6.0.4 "SocialSharing"
    cordova.plugin.autostart.permission 0.0.1 "AutoStartPermission"
    es6-promise-plugin 4.2.2 "Promise"
  • Dev machine OS and version, e.g.
    • Windows 10

Runtime issue

  • Device details
    • Tested on Asus zenfone 3 (android 8) and Asus zenfone 8 (android 13)

Related code:

In app.component.ts following code is executed in function ngOnInit():

this.platform.ready().then(() => {

      this.firebase.grantPermission().then(hasPermission => {
        console.log(":::::HAS PERMISSION: ", hasPermission);
      }).catch(e => {
        console.log(":::::HAS PERMISSION ERROR: ", e);
      });

      this.firebase.getToken().then(token => {
        this.sendToken(token!);
      }).catch(e => {
        // Error
      });

      this.firebase.onMessageReceived().subscribe(data => {
        console.log(":::::::RECEIVED NOTIFICATION: "+JSON.stringify(data));
        let tipoNotifica = data['tipo'];
        let dettaglioId = data['eventoid'];
        let titolo = data['title'];
        let testo = data['testo'];
        
        if(data.tap){
          this.navigazionePaginaDettaglio(dettaglioId, tipoNotifica);
        }else{
          alert("Nuova notifica ricevuta.\nTipo: " + tipoNotifica + "\nTitolo: " + titolo);
          this.navigazionePaginaDettaglio(dettaglioId, tipoNotifica);
        }

      });

    });

The code in this.firebase.grantPermission() is ignored, no permission is requested and no logs are written in console (but it should be correct, at least if I correctly understood what's written in the documentation about plugin usage under Android).

I also tried to add following configuration in config.xml file:

With this configuration when application is executed on recent phones (android 13+) a message appears asking to give permission to receive notifications, but nothing changes. Even with permission granted, no notification is received when app is in background.

Other information:

This issue seems to be present in recent versions of cordova platform. In apps developed with older versions of cordova (for example cordova 6.3.0) notifications are received.

@xJosee
Copy link

xJosee commented Dec 12, 2023

In my case the push notification only arrives when I am in the background, when I am inside the app it does not arrive.

Does anyone know if it is a configuration issue that I am missing?

@hal-berto
Copy link
Author

Strange thing is I tried with:
-Test project provided with this same plugin
-A clean cordova project with only firebasex plugin installed
-A clean capacitor project with only the push plugin (in this case it's not the cordova-plugin-firebasex, but a similar one)

In all these cases I experienced same issue: notifications are not received when the app is closed...
Isn't it a way to receive notifications on newer phones?

@dpa99c
Copy link
Owner

dpa99c commented Dec 15, 2023

Here is a screen recording showing the test project built with the latest plugin version (v16.3.0) and cordova-android@12 running on a Google Pixel 5a.
It shows the app receiving push notifications while in the foreground, background and not running (task killed).

@hal-berto I notice your test device is an Asus.
As outlined in #235, some non-Google OEMs (including Asus) have issues receiving push notifications from FCM when the app is not running (vs running in the background).
The proposed solution was to integrate the Autostarter library into this plugin.
However it appears this library is no longer maintained (no update for 2 years) so maybe an alternative needs to be found which is maintained before making any integration with this plugin.

@dpa99c dpa99c added runtime issue An issue related to app runtime ios relates to iOS platform Cloud Messaging Related to Firebase FCM / Push Notifications / APNS labels Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cloud Messaging Related to Firebase FCM / Push Notifications / APNS ios relates to iOS platform runtime issue An issue related to app runtime
Projects
None yet
Development

No branches or pull requests

3 participants