appfeel / node-pushnotifications

Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
MIT License
534 stars 126 forks source link

Body not working for Android #29

Closed jpike88 closed 7 years ago

jpike88 commented 7 years ago

{ title: 'This Shows, // REQUIRED body: 'Uhhh should i show', // REQUIRED topic: 'some_stuff' }

That body doesn't show in the android notification.

appfeel commented 7 years ago

Please see here: https://github.com/ToothlessGear/node-gcm/issues/279

jpike88 commented 7 years ago

My pull request was rushed. But this is a design issue inherent in either this library, node-gcm or gcm itself.

Like any library, It should be almost like a black box, where the most basic of arguments should achieve the desired effect consistently.

That above data object worked fine with APNS, so why can't it work fine with GCM?

Bear in mind, my use case is simple and probably representative of the majority of developers.

This is my entire script, so not sure what's going wrong here:

const settings = {
    gcm: {
        id: GCM_API_TOKEN
    },
    apn: {
        token: {
            key: KEY_PATH
            keyId: 'abc',
            teamId: '123',
        }
    },
};
const PushNotifications = require('node-pushnotifications');
const push = new PushNotifications(settings);

const registrationIds = [];
registrationIds.push('androidDeviceKey');

const data = {
    title: 'I SHOW', // REQUIRED
    body: 'ON ANDROID I DO NOT SHOW WITHOUT THE FIX I MADE', // REQUIRED
    topic: 'com.app.APP'
};

// You can use it in node callback style
push.send(registrationIds, data, (err, result) => {
    if (err) {
        console.log(err);
    } else {
        console.log(result[0].message);
    }
});

Edit: I read that message thread. Just made things even more confusing.

appfeel commented 7 years ago

The problem is with how google manages android push notifications, it's a mess. Could you show the code on your app? I can help you there.

Also you can see here how to get the data from the notification: https://github.com/appfeel/cordova-push-notifications/blob/master/src/android/com/plugin/gcm/GCMIntentService.java#L103

The main purpose of this library is the one you described, but we should not break old implementations. Maybe the changes you proposed could be integrated, not replacing the existing ones.

jpike88 commented 7 years ago

It seems any time I touch something related to Google, it always leads into a mess. I'll tweak my android code to suit it and figure more out about what's going on here.

jpike88 commented 7 years ago

What the hell. It now works. I didn't change anything today, just ran it again. Nice job Google.