Closed christocracy closed 9 years ago
@macdonst THANKS for the work on this feature.
I updated the plugin through cordova rm plugin and cordova add plugin, but from what I see (im new to cordova dev), the version i get is not the latest from git ? is there a normal delay between versions here and the ones we get from cordova add plugin ?
thanks in advance and again thanks for taking the time to improve this plugin.
PS: i figured out I should i use : cordova plugin add https://github.com/phonegap/phonegap-plugin-push ?
I am curious about a question of GCM payload. For example, if I need to show notification in the shade when app is in background, this plugin requires the payload to be like:
{
"to" : registrationId,
"data" :
{
"title" : "Portugal vs. Denmark",
"message" : "Data: please check score",
"myOwnData": "blablabla"
}
}
However, per "Hybrid messages with both notification and data payload" section of Google's official website: https://developers.google.com/cloud-messaging/concept-options
It mentions "notification" and "data" fields. And "title", "message" should be put in the "notification" so that Android will show them in the shade for background app. My speculation is that this plugin modifies the default Android behavior so that "title", "message" can be put in "data" field. Is this correct?
@rastermax if you do an add directly from the git url you'll get the current development version. It may or may not be stable.
@gongfan99 the latest version of the plugin should work with data/notification in the same payload.
Hi, I am not able to run the use-case #3 mentioned above. In "onnotification" function I'm saving message to local database. For both Android and iOS (and for both app is running in background and closed completely) notification alert is handled by OS and when user taps the message my code is running (saves to db). But, if I directly open app (not by clicking the notification), nothing happens (onnotification event is not called). I've tried combinations of content-available and other payload data in the examples. What is the point I am missing? I'm using ionic service to send notification messages.
background notification not working on android
I do receive the notification however when it opens the application the push notification wont work instead: Error in Success callbackId: PushNotification1215169404 : TypeError: Cannot read property 'id' of undefined
@barocsi then you need to look at where you access 'id' in your on('notification')
event handler.
Thanks @macdonst the problem was on my side.
has anyone been able to receive notifications in background on android? i cant seem to catch it at all and i always get an error when i do this as well
var pushPlugin = window.PushPlugin;
pushPlugin.on('notification', function(notification) {
})
var pushPlugin = window.PushNotification;
pushPlugin.on('notification', function(notification) {
})
All not working and all give me the same error, pushPlugin.on('notification') is not a function. How do i call the phonegap-plugin-push from my deviceready event?
PushNotification.init(cfg).on("notification",...)
?
@boyfunky just try the hello world example first maybe?
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/EXAMPLES.md
@boyfunky make sure you run "cordova plugin add phonegap-plugin-push" before you run "cordova build"
@gongfan99 yes i have already done that. @deceadmin how did you solve ur issue. I am having the same exact issue.
hi, maybe that can help. Recently I cleared my server code to send a notification and reading the docs about payload and what appears when app is off or in background here is what my server (nodejs) code looks like:
var notifMessage = new gcm.Message({ collapseKey: "MyAppGeneral", delayWhileIdle: false, timeToLive: 3, //weeks // what is shown notification: { title: "SpotiQuiz Message", icon: "icon", body: "THIS IS A TEST" }, //attached payload data: { nico1: "secret data1", nico2: "secret data2" } });
var regTokens = [obj.android_push_id]; //destination user push id
var sender = new gcm.Sender(GOOGLE_CLOUD_MESSAGING_KEY); //your GOOGLE PUSH KEY FOR YOUR APP
sender.send(notifMessage, {registrationTokens:regTokens}, function(err,response){ if(err){ console.log("notifUser:ERROR:Could not send android notification"); } else { console.log("notifUser:NotifSents:"+response); } });
Hope it can help.
On Tue, Mar 1, 2016 at 10:31 PM, Kingsley Simon notifications@github.com wrote:
@gongfan99 https://github.com/gongfan99 yes i have already done that. @deceadmin https://github.com/deceadmin how did you solve ur issue. I am having the same exact issue.
— Reply to this email directly or view it on GitHub https://github.com/phonegap/phonegap-plugin-push/issues/93#issuecomment-191037725 .
@boyfunky, i could not solve it
For Android it so doesn't work when app is in background.
Is there any alternate plugin. which do not have such issues?
I finally solved my background android issue! I would receive fine when app in the foreground, and would happily receive the tray notification when in the background, but my push.on('notification', function(data) {} would not fire at all in the background .... which is what I really wanted as I want to activate the GPS without the user having to click the tray notification. I knew I had to set content_available = 1 ... BUUUUT it is content-available and NOT content_available!! Silly mistake, but I think the "content_available": true, example in the docs threw me!
Hope that helps someone! (viewing the android debug logs helped me pinpoint the issue)
Hello All I receive notification in background but while tap on notification, i am unable to get data. One more thing i am using FCM for sending notification
No event-handler called with background app on iOS (it works on android), using GCM/FCM.
var message = new gcm.Message({
priority: "high", //needed when using FCM > iOS
data: {
title: "data title",
message: "data message",
"content-available": 1,
},
//otherwise no notification is received on iOS
notification: { title: "title", body: "message"},
// as documented in PAYLOAD.md
aps: {
"content-available": 1,
},
notId: 42
});
Is documentation here updated? https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#background-notifications-1
The "aps" object seem totally ignored on iOS ( aps.alert present or missing has no effects)
Does your iOS app have the background "notification" entitlement in the .plist? -- Snet form Gmail Mobile
It's a ionic app, and on xcode I've enabled the remote notifications in Background Modes. I've "remote-notifications" in UIBackgroundModes in the info.plist.
@bfx This may be a bit dated but I'm working through the same documentation now on version 2.0.x version of the code. I believe the docs you are referring to above referencing the payload are in fact the docs for the APNS version of the API. If I understand it properly, node-gcm sends to google who turns around and sends to APNS for you. https://firebase.google.com/docs/cloud-messaging/http-server-ref indicates you should likely be sending something like:
var message = new gcm.Message({
priority: "high", //needed when using FCM > iOS
data: {
title: "data title",
message: "data message",
},
notification: { title: "title", body: "message"},
content-available: 1,
notId: 42
});
Note the content-available:1
is no longer a child of aps
. I'm assuming (but don't know for sure) that fcm turns around and sends something like you see documented in Payload to APNS.
Hope that helps, but as with most things, YMMV.
Cheerio.
@coderroggie btw content-available should be "content_available": true,
This thread has been automatically locked.
This plugin is unable to receive notifications while in the background since it doesn't implement application:didReceiveRemoteNotification:fetchCompletionHandler:
Discussion
Clearly this logic in
didReceiveRemoteNotification
is useless, since that method is only called in the foreground.