[Plugins] We've added push notifications to Build.

  • 1
  • Announcement
  • Updated 5 years ago
Here is some more information :)

https://build.phonegap.com/blog/intro...

If you have any issues with it let us know and we'll be happy to help!

Hardeep Shoker
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes

Posted 8 years ago

  • 1
Photo of Red2678

Red2678

  • 255 Posts
  • 0 Reply Likes
Wooooo!
Photo of Mark Eckard

Mark Eckard

  • 7 Posts
  • 0 Reply Likes
Trying to get this to work ...
=========
Added this to config.xml:

gap:plugin name="GenericPush"
=========
Js includes in head of index.html (using jQuery Mobile):

script type="text/javascript" src="phonegap.js"
script type="text/javascript" src="PushNotification.js"

========
In gc.js (my javascript):
//after deviceReady and JQM mobileinit

try
{
var pushNotification = window.plugins.pushNotification;
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
alert(txt);
}
=========

I get the error description
"Cannot read property 'pushNotification' of undefined"

What am I doing wrong?
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes
Hey Mark,

What's your application id? I'll look at the app and diagnose the issue.

Hardeep Shoker
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes
Ah, nevermind, I see you've resolved the issue bellow.
Photo of Marriott Perez

Marriott Perez

  • 7 Posts
  • 0 Reply Likes
I keep getting 'There is a problem parsing the package' when trying to install the apk on my Android Device after adding the GenericPush plugin to my config.xml file. I'm using Phonegap 2.0.0 but I also tried with 2.2.0

Thanks for the help!
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes
This may be due to an invalid package name. If the package name is not a valid java class name you will get the error above. Perhaps that's the issue you are facing?

Hardeep Shoker
Photo of Mark Eckard

Mark Eckard

  • 7 Posts
  • 0 Reply Likes
This one fixed the problem with the Android build:

In config.xml:
gap:plugin name="PushPlugin"
not, name="GenericPush" as I've seen in some references.

But still catching error:
"undefined is not an object" in the iOS build for the line
var pushNotification = window.plugins.pushNotification;
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Download the code from Oscar Abilleira Muñiz from this thread: http://community.phonegap.com/nitobi/...
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
In the same thread I posted another test, using navigator.notification.beep(1) before the "alert" it sounds even in backgroun but just for a moment, the the app is killed...
Photo of Mark Towse

Mark Towse

  • 2 Posts
  • 0 Reply Likes
I have this issue but this fix doesnt seem to have resolved it... help!.. in my config.xml I have "" is this not correct?
Photo of Mark Towse

Mark Towse

  • 2 Posts
  • 0 Reply Likes
plugin name="PushPlugin" value="com.plugin.GCM.PushPlugin"
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
try
< gap:plugin name="GenericPush" />
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
I downloaded the www folder from here: https://github.com/hollyschinsky/Phon...

I did this:
I changed Sender_ID from index.js to mine, I uploaded the zip file to PhoneGap Build and installed the apk on my Android 2.2 device.
It didn’t work so I put a try/catch handler to catch the error.

The error caught was: successHandler not defined
I supposed that it needs to be defined absolutely so I changed this line:

pushNotification.register(successHandler, errorHandler,{“senderID”:”**********”,”ecb”:”onNotificationGCM”});

to that:
pushNotification.register(app.successHandler, app.errorHandler,{“senderID”:”**********”,”ecb”:”onNotificationGCM”});

I installed again on my device and there was no error anymore from try/catch.
But a new error came out from function’s errorHandler:function(error):
It says:

“Class not found”

I cannot find out what’s wrong. I haven’t changed anything to the code provided except the Sender_id!

Can anyone help please?

P.S. The only thing I did is that I renamed the file cordova2.3.0.js to phonegap.js.
Photo of John Saya

John Saya

  • 68 Posts
  • 7 Reply Likes
I was testing out the plugin the other day and spent a few hours trying to get it working, and then realized the sample code supplied at https://github.com/phonegap-build/Pus... has errors in it, specifically the Android section:

It looks like this:


// Android
function onNotificationGCM(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
alert('registration id = e.regid);
}
break;

case 'message':
// this is the actual push notification. its format depends on the data model
// of the intermediary push server which must also be reflected in GCMIntentService.java
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;

case 'error':
alert('GCM error = e.msg);
break;

default:
alert('An unknown GCM event has occurred);
break;
}
}


But look closely and you'll see spots where there are missing apostrophes and plus signs. For example:

alert('registration id = e.regid);

should be: alert('registration id = ' + e.regid);

The same for:


case 'error':
alert('GCM error = e.msg);
break;

default:
alert('An unknown GCM event has occurred);
break;


It should be


case 'error':
alert('GCM error = ' + e.msg);
break;

default:
alert('An unknown GCM event has occurred');
break;
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Can you upload working zip file?
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes
Hey John,

I'll bring this up with the team. Thanks for the heads up!

Hardeep Shoker
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Hardeep,
Looking around the forums I come up with bad news for PhoneGap Build users:
Look at this:
http://permalink.gmane.org/gmane.comp...

It seems that the javascript code cannot get executed if the app is not running. The only solution, that also suggested and worked on the mentioned forum, is to to create a java plugin to raise a notification on the statusbar, instead of trying to reach your project's javascript code. This can be done only with Phonegap Desktop, not PhoneGap Build, of course. It's a pity, because we had great expectations from the PushPlugin and spent 3 days on this...

If someone wants to follow the solution using PhoneGap Desktop, here is the thread's url, you should start with Arjan de Vries | 18 Oct 2012 17:06 answer:

http://comments.gmane.org/gmane.comp....

But, Hardeep, can you add this functionality to PhoneGap Build also?

Competitors (appmobi, tiggzi etc) support push notifications already.
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
I'm currently looking into the referenced solution, and will report back once I have had a chance to evaluate it.
Photo of Hardeep Shoker

Hardeep Shoker

  • 1941 Posts
  • 89 Reply Likes
Hey everyone,

Sorry for not being able to respond fast enough, it was the weekend over here :) I'll look into the issues you've discussed and either provide a response myself or have another team member look into the specific issues.

Thanks for you feedback,

Hardeep Shoker
Photo of Sean O'Gorman

Sean O'Gorman

  • 33 Posts
  • 0 Reply Likes
Thanks for the update!
Photo of alia

alia

  • 21 Posts
  • 7 Reply Likes
Hello,

It's very sad that after six months of discussion and having the maintained plugin by Pushwoosh ready with lots of features: (https://github.com/shaders/pushwoosh-...), PGB decided to adapt some extremely old unmaintained version of some GCM (formerly C2DM) plugin which even doesn't work when the app is closed. Of course, all other advanced features, such as lighting up the screen on push notifications, multi-push notiications mode, flash lights, play custom sound, etc are missing as well.

The code is dreadful there, using statics from the service (when Java VM could be shut down and all your statics will be NULL), not creating Pending Intent. Why not to trust push notifications expert and trying to reinvent the bicycle?

It would be quite easy to make the Pushwoosh plugin provider-independent by forking the plugin and disabling the device registration with Pushwoosh, but leaving all the features and benefits in place. Plus it's been tested by thousands of users!

I'm very sorry for Phonegap users, we did our best.
Pushwoosh team
Photo of Red2678

Red2678

  • 255 Posts
  • 0 Reply Likes
....this is a bummer. The complete lack of plugins for PGB is making it very hard to use...moreover, I totally agree with the above post.
Photo of Mike Harris

Mike Harris

  • 77 Posts
  • 17 Reply Likes
First, thanks to everyone for the feedback on our release of GenericPush. Unfortunately, the plugin did not live up to everyone’s expectations and we actively working on fixing the problems and will post a new version soon as we can.

So why did we create a generic push plugin? It seemed like the correct place to start. We essentially forked an existing plugin that was a part of the PhoneGap plugin repo. However, this repo has showed it’s limitations, which we plan on resolving. The current blocking limitation is getting push notifications to be captured when an Android application goes into the background.

You may also be wondering we didn’t just provide a third party plugin to handle push notifications? This is something are still planning to support and PushWoosh will be our first plugin, however, because of administrative roadblocks we weren’t able to provide it before the GenericPush plugin.

We have also heard loud and clear that we need to be able to provide a better mechanism for supporting third party plugins and it is high on our backlog.

- Mike
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Thanks for take in consideration our ideas :) Is there any change of adding in this "new push plugin" a way to give notifications to the user when the app is in the background
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
We are actively working on a solution for this. No ETA as of yet.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Great!!! thanks again
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Finally, I have installed Phonegap desktop, and installed Pushwoosh plugin. It works like a charm. I have also changed the code a bit to be able to send push messages without using pushwoosh website. I will write down the steps for reference in a future post.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Good news for the new generic push plugin...

https://build.phonegap.com/blog/statu...
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
An update to the GenericPush plugin is now on the build servers. This adds the status bar notification when the app is in the background. In addition, this update now surfaces any custom key / value pairs up to the JS layer, if present in the notification payload. Finally, you can look at the 'foreground' flag to determine whether the notification came in while the app was in the foreground, or whether it was resumed by the user touching the notification when the app was in the background. The examples and documentation have been updated to reflect these changes.

check out https://github.com/phonegap-build/Pus... and https://github.com/phonegap-build/Pus... respectively.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Great!!! but I tried to update the content in this link in Android
https://github.com/phonegap-build/Pus...

When the app is open push notification works well, but if it is in the background when the push notification is recived appear a message that indicates that the "the app has been closed"...

Anyone with the same problem?
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
I'm not seeing this. Can you post the exact wording of the message?. Also, when you exit the app, are you using the back button or the home button?
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I'm using the home button... If I use the backbutton nothing happends ..

The exact message (in English) is "Unfortunately, -name of the app - has stopped" and show a ok button.
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
ok. What is the exact wording of the message?
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
The exact message (in English) is "Unfortunately, -name of the app - has stopped" and show a ok button.

Thanks in advance :)

Tested in HTC one X - Android 4.1.1 (JB)
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
That sounds like your app is crashing on exit. Can you provide the appID so I can take a look?
Photo of Sean O'Gorman

Sean O'Gorman

  • 33 Posts
  • 0 Reply Likes
Bob, I am seeing the same "Unfortunately, -name of the app - has stopped" when pushing a background notification to Android
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
hmmm. I wonder if it has something to do with the content... Can either of you post the payload that your server is sending?
Photo of Sean O'Gorman

Sean O'Gorman

  • 33 Posts
  • 0 Reply Likes
Bob, Here is the data sent to GCM for a device using PGB app ID# 182234

{"registration_ids":["APA91bG8Ry2Z-yaiX2qSAMuym5o4vLs4cDkI7hzfhu9Ntc6ZtonoqmucE23qGSj6sKV70GaekmCBsPPyxF4Y_BCxQQxdoUFjPE3KfjdCK3p9qBsC-hxfkCKDhTYOKc18jAZYq8-zl71eVYlKN6-eAOWIYQjUhhhO2xE3XOxupN4jBjC2Xe_lyqw"],"data":{"message":"TEST MESSAGE"}}

If the message is received in the foreground it displays fine. If it is received in the background it throws the "Unfortunately, -name of the app - has stopped"

Thanks for all the help!

Sean
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Here's the content sent to my app ID#167401

{"registration_ids":["APA91bFsgH1Q_EL-kvQhDEIzVpDfD039t2LjxoWb8sg6mLMkuFS8P4BcxMmac_Nb4G2WprsbDX1nCtxeyy7oKutWMkVtQcZ34QTJZfQu2YA90rtEZjD-ukvmQrADBqNYn3c2cnPY4v8wkOlm_iSNCF9c6h49WxMg76osjc5T9gz7weZF_2KdHR0"],"data":{"message":"este es un mensaje de prueba"}}

The result is the same that in Sean's app, in foreground works fine, but in background the "sttoped" message.
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Thanks guys. thats exactly the info I needed!

on it.