fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 989 forks source link

not get any notification when app closed or in the background #251

Open kenchu1178 opened 7 years ago

kenchu1178 commented 7 years ago

when app closed and in the background. push notification show in the bar. after taped it. app will show up and launch to start. but How can I get the notification in the app

bendspoons commented 7 years ago

See Payload Example in the Readme section. Add "click_action":"FCM_PLUGIN_ACTIVITY" when sending message. Solved my Problem with Notifications received while in background or closed.

jonathan-chin commented 7 years ago

@bendspoons I'm curious, the Payload Example also mentions a sound key, but I haven't been able to get it to work. Have you?

kenchu1178 commented 7 years ago

THANKS, WORKING NOW

bendspoons commented 7 years ago

@jonathan-chin Yeah, sound works, but i didint do anything special for that. But be aware that you do not have to set the sound to true or sth like that, set it to "default" (as string)!

If you are familar with PHP, try https://github.com/Paragraph1/php-fcm for sending. I tried that Tool and it works perfect. (Now i wrote my own for my company cause we needed to many special features which arent included in many repos fpr fcm)

Example (shortened) $note = new Notification($title, $body); $note->setClickAction('FCM_PLUGIN_ACTIVITY'); $note->setSound('default');

jonathan-chin commented 7 years ago

@bendspoons I'm using node-fcm and this is the payload I'm sending:

let message = {
        to: token,
        notification: {
            tag: "new_messages",
            title: `You have ${count} new message${count == 1 ? '' : 's'}`,
            body: 'Click to read them!',
            sound: 'default',
            //badge: "100"
        },
        data: {
            type: "chat"
        },
        collapse_key: "new_messages"
        };

the sound flag is there and set to default but my phone doesn't do anything.

do you get vibration too?

koenfaro90 commented 7 years ago

Thanks! Should be pointed out a bit clearer in the docs I'd say, but works fine!