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 never arriving to the device #441

Closed
Zerokk opened this issue Jun 30, 2020 · 6 comments
Closed

Push notifications never arriving to the device #441

Zerokk opened this issue Jun 30, 2020 · 6 comments
Labels
android Relates to Android platform runtime issue An issue related to app runtime support Support is being requested but not a necessarily a bug

Comments

@Zerokk
Copy link

Zerokk commented Jun 30, 2020

Current behavior:

When I send pushes from my custom Firebase push server, they never arrive to the device. This server used to work in the past, with this same plugin. It acts as a scheduler that reacts upon some live queries, and sends the push at some specific time. Although the logs of the server show that it's actually sending the push with no trouble whatsoever (with the firebase-admin lib), it does not arrive into my device.

The reason is simple: server's code hasn't changed, and it used to work perfectly. The whole part that seems to be problematic, is in the client.

Expected behavior:

Push notifications should be correctly arriving.

Steps to reproduce:

  • Installed the FirebaseX plugin for Cordova and @ionic-native/firebase-x.
  • Downloaded the google-services.json from the Firebase console. Placed it in proyect's root folder, platforms/android, and in platforms/android/app. Just in case, since none of them were working.
  • Re-build the APK.

Environment information

  • Cordova CLI version

    • cordova -v
  • Cordova platform version
    9.0.0 ([email protected])

  • Plugins & versions installed in project (including this plugin)
    cordova-plugin-androidx 2.0.0 "cordova-plugin-androidx"
    cordova-plugin-androidx-adapter 1.1.1 "cordova-plugin-androidx-adapter"
    cordova-plugin-device 2.0.2 "Device"
    cordova-plugin-firebasex 9.1.2-cli "Google Firebase Plugin"
    cordova-plugin-geolocation 4.0.2 "Geolocation"
    cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
    cordova-plugin-ionic-webview 4.2.1 "cordova-plugin-ionic-webview"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-whitelist 1.3.3 "Whitelist"

  • Dev machine OS and version, e.g.

    • Windows 10
      Windows 10 v.1903, SO 18362.900

Runtime issue

  • Device details
    • Xiaomi Pocophone F1
  • OS details
    • Android 9

Android build issue:

  • Node JS version
    • 14.1
  • Gradle version
    d----- 25/06/2020 13:57 4.10.3 d----- 25/06/2020 13:57 4.6 d----- 25/06/2020 13:57 buildOutputCleanup d----- 25/06/2020 13:57 vcs-1
  • Target Android SDK version
    • android:targetSdkVersion in AndroidManifest.xml
      --> I can't find this, no idea why. May this be a problem?
  • Android SDK details
    • sdkmanager --list | sed -e '/Available Packages/q'
      --> doesn't work either, although I can build the app and it works good (except for FCM pushes).

Related code:

This is my server's code, as there's no related client code rather than just importing the FirebaseX module into my main module.
  /**
     * This method will check all the scheduled pushes (push objects that are scheduled to be sent throughout the day),
     * and send them when their send date is previous to the current date.
     * 
     * Returns "true" when all the promises of the saved objects have been resolved, and "false" when some haven't.
     * As the objects get removed from the pendent pushes list, this is useful for trying to save the remaining objects.
     */
    public async checkSendPushes() {
        const today = new Date();
        const promises = [];
        console.log("[PushScheduler] checkSendPushes() -> Checking " + this.scheduledPushes.length + " pushes...");
        for (let i = 0; i < this.scheduledPushes.length; i++) {
            const schPush = this.scheduledPushes[i];
            // Check whether the sendDate has already passed; therefore, send the push (the delay won't be high)
            // --> Also, check if there's no date to send. That means it's an immediate push.
            console.log("Scheduled push date: ", schPush.date);
            if (!schPush.date || moment(schPush.date).isBefore(moment(today))) {
                console.log(`>>> 🚀 Sending push!`, schPush.pushObject.notification.body)
                promises.push(
                    this.firebaseRef.messaging()
                        .sendToDevice(schPush.userFCMToken, schPush.pushObject)
                        .then(res => this.scheduledPushes.splice(i, 1))
                        .catch(err => {
                            console.log("[PushScheduler] Error sending push: ", err)
                        })
                );
            }
        }
        try {
            await Promise.all(promises);
            return true;
        } catch (err) {
            console.log("[PushScheduler] => checkSendPushes  ERR: ", err)
            return false;
        }

    }


My intuition keeps telling I'm doing something wrong somewhere in my ecosystem, but it doesn't make much sense that I don't get any kind of error and this thing keeps not working. The package name is correct, the plugins seem to build well, and even the Gradle Build gets the google-services.json file and puts it into the APK — which makes me think that the plugin is correctly gathering all its needed info and files to work.

Being it this way... why doesn't it work? I've been struggling with this problem for weeks, and this is starting to become a very serious problem I can't find ANY solution to. I tried literally every StackOverFlow solution, and none of them work.

This is a desperate call for help. I will appreciate a lot every effort to fix this.

Thank you.

@dpa99c
Copy link
Owner

dpa99c commented Jun 30, 2020

Try building and running the example project to eliminate possible problems in your codebase and use its built-in FCM v1 API messaging client to rule out any issues on your server-side.

Since you are testing on a Xiaomi device, bear in mind that there is an issue which will cause notifications not to be received if the app is not running - see #235.

This plugin is in use in production in numerous apps (including my own) and therefore the issue is specific to you rather than a generic issue affecting all plugin users and for that reason I'm closing this as it's a support issue not a plugin bug.

@dpa99c dpa99c closed this as completed Jun 30, 2020
@dpa99c dpa99c added android Relates to Android platform runtime issue An issue related to app runtime support Support is being requested but not a necessarily a bug labels Jun 30, 2020
@Zerokk
Copy link
Author

Zerokk commented Jun 30, 2020

Pushes don't work in Xiaomi devices? How's that? This was working for me just a couple of months ago, so that cannot be the problem. I re-organised the project, so I updated plugins just like yours, and that's what actually led me to this problem.

Does installing the AutoStarter plugin you mention in #235 currently work for fixing the Xiaomi problem that you mention?

Thank you.

@dpa99c
Copy link
Owner

dpa99c commented Jun 30, 2020

Pushes don't work in Xiaomi devices?

The issue with OEMs like Xiaomi is they automatically blacklist apps from autostarting, preventing them from being launched when a push notification is received when the app is not running - it works OK if the app is running in foreground or background.

Does installing the AutoStarter plugin you mention in #235 currently work for fixing the Xiaomi problem that you mention?

It is supposed to resolve the above issue though I don't have such a device to test on so I haven't tried it to confirm this is the case.

@Zerokk
Copy link
Author

Zerokk commented Jun 30, 2020

I was just making some testings and the pushes are not being received even if the app is in background/foreground, so I guess that my problem's root is not in this issue.

It is supposed to resolve the above issue though I don't have such a device to test on so I haven't tried it to confirm this is the case.

So I guess this plugin is still not embedded in your FirebaseX plugin?

edit: weirdly enough, when push notifs were working well in my app, they worked even with the app totally closed (not being in background). With the same device.

@dpa99c
Copy link
Owner

dpa99c commented Jun 30, 2020

So I guess this plugin is still not embedded in your FirebaseX plugin?

No but if someone with an affected device is able to make and test a PR containing it, I will merge it.

@gmbad
Copy link

gmbad commented Oct 4, 2021

hello @dpa99c.

On my device xiaomi is not working when the app is closed.

On my samsung everything works correctly.

I am available to test possible new releases to fix this problem.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Relates to Android platform runtime issue An issue related to app runtime support Support is being requested but not a necessarily a bug
Projects
None yet
Development

No branches or pull requests

3 participants