PhoneGap build support for Push Notification plugin

  • 22
  • Problem
  • Updated 4 years ago
  • Acknowledged
Hi Guys

In my application I want to use Push Notification plugin for iPhone, so when I looked into it I found the Push Notification plugin here https://github.com/purplecabbage/phon... .

But then I found few more links which says phonegap build supports only Child Browser plugin. Following are the links where I found this information
http://stackoverflow.com/questions/10...
https://build.phonegap.com/docs/plugins

One of the link is from documentation itself. It looks like I wouldn't be able to do push notification in my application. If its true than it will be a major set back for my project.

Is there any work around to use these plugins and getting the ios build as well?
Please help me.
Photo of Uday Pratap Singh

Uday Pratap Singh

  • 27 Posts
  • 0 Reply Likes

Posted 8 years ago

  • 22
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I tested it but it's not what I was looking for and waiting ;(

Push notifications only can be showed using alerts or phonegap notification system and there's no option to show the notification in the status bar.

And the most disapointed aspect, the push notifications only works if the app is opened not in the background.

Interesting but not usefull for my app.
Photo of Mark Eckard

Mark Eckard

  • 7 Posts
  • 0 Reply Likes
I think we'd all like to get some clarification on this...

My idea of a push notification is where a server sends a message to an app/device combination and that message (accompanied, perhaps, by a sound) is displayed, even if the app is not in use. It can also sets a badge on the app icon. The notification is a signal for the user to open the app.

I'm getting the feeling that this new Push plugin only displays notifications when the app is open ... which really isn't much help.

Please tell me I'm mistaken.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I think the same like you... probably we're are talking about "background push notification"... Probably this is a limitation of phonegap, that can't run in the background.
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Maybe there is a problem in the provided phonegap build code that prevents the android system from waking up the app. I am saying this because the push notification is definately able to work even if the apps are not running. Here, it states clearly: http://developer.android.com/google/g...

"An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions"

So, maybe the event inside the app is not triggered when it should by the Android system due to misconfiguration.

Personally, I haven't managed to register my device on GCM because the example code from here (https://github.com/hollyschinsky/Phon... work and I would be grateful if someone uploaded a working phonegap build sample.
Photo of Steve Eschweiler

Steve Eschweiler

  • 1 Post
  • 0 Reply Likes
Pushwoosh does this... Should add support to PhoneGap build for this down the road!
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Does Pushwoosh plugin works even with the app in the background? Does it uses the status bar?

In my test with this plugin, when I send from a server and the app is in the background the notification (an alert) doest apear, but when I open the app the message is still there... I don't know if this notification is write when I reopen the app or it's still here, in the background, but the app has no way to show like the status bar...
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Dear sir, in my opinion this a a problem in the provided phonegap build code that prevents the android system from waking up the app. I am saying this because the push notification is definately able to work even if the apps are not running. Here, it states clearly that the Android system is able to wake up the app through Intent.
Because I wasn't able to make the plugin work when compiled it with phonegap, would you be so kind to send me the code that works for you? I mean the www folder.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
For android first we need to go to https://code.google.com/apis/console

- And thereunder overview ab you'll find the project numeber (idenfitication for index.html file)
- Under services tab active the google play messaging for Android
- Under API acces you can generate a server key for using in your site php file if you want to test.

Try this code ( I tested in phonegap build), remember put your identification ID In the correct place for android.

http://www.filesend.net/download.php?...

You have to put your senderid in the correct place for android.... under ios ever aperar a "aps-enviromment" autorising missing.

For testing it (under android) ) I send a message from muy website using this php file. (note that if your app is signed the id get in the config.xml file must macht with the certifcate)

file.php



<?

// Replace with real BROWSER API key from Google APIs
$apiKey = "your google api key";

// Replace with real client registration IDs (apears on push test)
$registrationIDs = array( "device_registration_id", );

// Message to be sent
$message = "this is a test message";

// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';

$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);

$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

echo $result;

?>

Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
That's great. I really thank you very much. It works like a charm.

I noticed that, indeed, the message does not appear if the app is not shown. But, this does not mean that the event when a message is received is not triggered. Which means you could use this service to make your app make a silent sync in the background.

The message is received by the app and handled internally so you can execute whatever js code you wish.

Now, I am trying to make the app put itself in the foreground via javascript. One method could be the Android intent capability. But I am not sure that Phonegap Build supports this.

I will let you know as soon as I have any update on this.

Thanks again.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I make a new "test" and using "navigator.notification.beep(1);" before the "alert" works in background when there's a new notification push and even with the device locked.... but just for a cuple of minutes... the the app is killed by android

So, we have two problems:
1- we need a way to give the notification from background using the status bar (I ever thought that it will be included in push notification plugin)
2- we need to make the app keep active all the time in background, now is killed by android system (I don't know how to solve this) Agree with Kostas David in the following post. Push notification must work with the app inactive in background
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
I have altered your code a bit by substituting the "alert" command with an Ajax post request to my server. I found out that when the app is running in the background, even if the screen is locked, the Ajax post request is implemented successfully. But when the Android system terminates the app NO EVENT is triggered that's why NO CODE is executed.
As to answer to your questions:
1) This would be great, I agree.
2) If we keep the app active in the background the GCM loses its purpose, which is NOT to run an app in the background. If you don't have a resource problem (battery, CPU, RAM) running an app in the background you could just use settimeout function and check the server for new messages every n minutes by making Ajax requests. But that's not the case! We are struggling to make this work just to avoid this.
I hope that Phonegap build team will correct it soon, or there is no reason of maintaining it!
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I'm totally agree with you... this plugin has no sense if the app must be active in the background.... but I'm not sure if phonegap build team has intention to "solve" this issue or their include this plugin only in this way...
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
I'm pretty sure that the problem has to do with the broadcast receiver event code of phonegap build native code. I hope they will fix it pretty soon because we do not have access to this code because phonegap build embeds it automatically to our apks.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I hope someone from the team read this thread hehe ;)

But even with this solved.. the other problem is how to give the information to the user from background
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Have you tried this?
Adding on index.html the line:
document.addEventListener('push-notification', onNotificationGCM, false);
before the:
document.addEventListener('deviceready', onDeviceReady, true);

I don't have the time to check it right now, but I hope it works.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Great!!!

I add this line 15 minutes ago, the device was locked during all this time and the push notifications are working :).... when I send one the device give the sound alert.

What's exactly doing this line ? the app is still working in background now?...

Now, if this is the solution, we have find a way to show the "notification" to the user from background... wait for status bar plugin?

I have also to test under ios that is not working in my test, probably due certificates
Photo of Mark Eckard

Mark Eckard

  • 7 Posts
  • 0 Reply Likes
Android push is working for me (except for updating the status bar), but when I try to instantiate the pushNotification object with iOS, namely:

pushNotification = window.plugins.pushNotification;

I catch an error: 'undefined' is not an object

Why would the object be successfully created in Android but not in iOS? Can't really move forward on the iOS side until this is resolved.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
in IOS in my tests I have this error:
"no valid aps-enviroment entitlement string found for application"

I have rebuild my provisioning certificates adding push notifications... but same result.
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Oscar, with the line you added to the code now it works even if the app is closed? Because I don't see any difference. When the app is closed no code is executed. I can check if my app is running through PhoneGap Build remote debugging console.
Mr Eckard, you are able to make it work even if the app is closed?
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
It worked for a while but after some hours of inactivity stops to work :(
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Update:
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....
Photo of Matt Chatterley

Matt Chatterley

  • 24 Posts
  • 2 Reply Likes
Thanks for sharing the results of your research - looks like you're right as far as I can see. It's a real shame as I suspect it means we're going to have to ditch PGB :(
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Thanks... finally bad news :(
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Don't give up on us just yet :). I'm currently looking into why the notification is not displayed when the app is not active. stay tuned.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Great news ;)
Photo of Rob Porter

Rob Porter

  • 5 Posts
  • 0 Reply Likes
Has there been any progress in this? It has been a month now. We went and developed with PushWoosh because you said it is supported, now we find it is not. Why say you support it still?
Photo of Khurrum

Khurrum

  • 10 Posts
  • 1 Reply Like
It basically means that the PhoneGap Build team need to add specific functionality alongside this Plugin. Like having a consistent message format for the push notification and creating specific popups or badge changes in certain situations.

Could perhaps also create a local file to store Push notifications with time stamps so that when the app comes online it can respond to them.

Its understandable if we have to work with certain constraints in order to use the Build service.
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
I agree with you. If they implement the functionality you mentioned then the plugin will be useful. But, in my opinion it should have been mentioned somewhere in the documentation that lacks of this ability, so that we didn't spend so much time trying to find out what's wrong.
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Just a minor update:
Even if the Phonegap Build team adds this functionality, this does not mean that the plugin will work out of the box. If you follow the above mentioned thread you will see that the messages are not delivered if you reboot the phone.

I think that you always must have the chance to edit Java code even with PGB. In my opinion the most important update of PGB is to be able to install your own plugins which means to be able to upload native Java libraries. Why is it so hard? I suppose that PGB runs a lot of instances of Android SDK and other SDKs, so it would not be hard to give the permission to the users to also upload Java libraries.

BTW, does anyone know any other service like PGB but with the above described functionality?
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
There is a push notifications implementation from a similar to PGP environment but the service is not free:

http://www.applicationcraft.com/devel...
Photo of alia

alia

  • 21 Posts
  • 7 Reply Likes
Hi,

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 Matt Chatterley

Matt Chatterley

  • 24 Posts
  • 2 Reply Likes
It's a terrible shame and for us at least, a killer blow to PGB :(
Photo of Andrew Ames

Andrew Ames

  • 3 Posts
  • 0 Reply Likes
well PGB is dead to me now, ill just have to go Phonegap style and use pushwhoosh
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Hi All,

We are currently looking into why the notification plugin does not display an alert when the app is not active. Bear with us while we sort this out.
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
Bob, if you see this post you will understand why the alert never reaches the app when it's shut:

http://permalink.gmane.org/gmane.comp...

I also recommend you to see the Arjan de Vries | 18 Oct 2012 17:06 answer on how to solve the problem and make it usable:

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

I also suggest you that you embed Pushwoosh notifications.

Hope for the best!
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I think that would be more important make the generic pluging to work in background adding notification in status bar or similar, before pushwoosh or other services
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
I disagree because the phonegap push plugin has poor code in it causing many major issues that have been previously mentioned by other posters.
In my opinion the best thing is to transform pushwoosh plugin so that it does not need to communicate with pushwoosh only.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
But there must be a plugin that works with own services... Even with an own server... If they use the pushwoosh code, and work in this way, Will be ok for me
Photo of alia

alia

  • 21 Posts
  • 7 Reply Likes
You can easily remove the part where you connect to the Pushwoosh service and replace it with something else. It's not a problem.

After all, the Pushwoosh team is ready do it by themselves just to make the plugin work and also make everybody happy :)
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
So we are all agree now hehe.
Photo of eschweiler

eschweiler

  • 4 Posts
  • 0 Reply Likes
Yeah, Pushwoosh would be better...
Photo of Kostas David

Kostas David

  • 23 Posts
  • 0 Reply Likes
The best would be to be able to use your own push server with the full functionality of Pushwoosh.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
That would be perfect
Photo of Khurrum

Khurrum

  • 10 Posts
  • 1 Reply Like
Good luck.
Photo of Matt Chatterley

Matt Chatterley

  • 24 Posts
  • 2 Reply Likes
Bob - are there any plans to introduce local notifications (e.g. support for notification areas) as per this post: http://community.phonegap.com/nitobi/... ?
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Hi Matt,

We are actively looking into which plugins might make sense to add to PhoneGap Build. Local Notifications is a recurring request, so we will certainly consider it. No specific plans to share at this point though.
Photo of Matt Chatterley

Matt Chatterley

  • 24 Posts
  • 2 Reply Likes
Bob - thanks very much for the clear answer, very much appreciated. It's a pretty critical one to us, but at least knowing the score helps us to make some plans!
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 Claes Gustavsson

Claes Gustavsson

  • 69 Posts
  • 1 Reply Like
Good to hear that PushWoosh is going to be the first plugin, since PushWoosh is great! It is easy to implement in a ordinary Phonegap project, and without it in Phonegap Build, I for one cant use the build service. And I really would like to since the build service is fantastic!

Can you say when the pushwoosh plugin will be included in the build service?
A month? Six months?

Thank you all at Phonegap for some great work.
Manmade
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Good news for generic push

https://build.phonegap.com/blog/statu...
Photo of Markus Hofer

Markus Hofer

  • 12 Posts
  • 0 Reply Likes
Can somebody please confirm for me that the GenericPush Plugin in able to deliver Messages even when the App is closed on iOS.
Thank you very much.
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Yes. Notifications will be delivered even if the app is closed and will follow your preference settings under Notifications in the Settings app.
Photo of elliottg

elliottg

  • 2 Posts
  • 0 Reply Likes
Thanks Bob. Is this for PhoneGap Build also?
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Yes. both.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I have a little problem (only under android )... actually this plugin works fine in my app, but now I want to send from my server an aditional key and not only the message, works fine but the value of the key is the same for minutes even if a new push notification is sent using other value.

Searching on the net I found a posible reason "pending intent is not being updated"... The problem described is exactly what is happening in my app... and someone offer this solution "update pendding intent..."

http://stackoverflow.com/questions/13...

Any idea about this issue...
Photo of Bob Easterday

Bob Easterday

  • 174 Posts
  • 14 Reply Likes
Hi Oscar, A solution for this has been posted to the repo. If you are building in Phonegap, it is available now by re-downloading the plugin. This solution should be available in PhoneGap Build by tomorrow.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Great!!! You are so fast
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Thanks Bob, all works perfect, but I have a "problem" when I try to get the value from this "aditional" data sent by push notification when the app is "stoped" in the background. I don't know if I'm doing something wrong or that's the way on this pluging works :)

I have an app where push notifications woks like a charm. From my server I sent to kind of information using push notification and I also sent, with the message, other data to identify what kind of "information" I am sending. The idea is use this "other information" to open an specific page from my app. In my code I "save" this value and make the app show the page acording the value of it.

All works good when the app is in the background but active, when the push notification comes, the app open the page acording the "extra data" sent by push notification, both in android and ios.

The problem apear when the app is not active in background, under ios that's only happends when the user close the app (so that's not a problem), but under android the O.S. automatically close the app after some minutes, so when the push notification is coming, the messege is correctly recived but the extra value seems not be "recived" by the app, the result is that the app didn't open the expected page.

My question is if this is way on the push notification plugin works under android... or I'm doing something bad with my code...

It's posible to save this "extra value" sent in a push notification when the app is in the background, but closed by the O.S.??

Thank's in advance and sorry for this poor english ;)
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
I have also tested this "issue" using the example code with the same result, when the app is closed by Android O.S., when push notification is recived no message or other data is showed in the app.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Can anyone confirm if this is the way on this plugin works :)
Photo of Matt Chatterley

Matt Chatterley

  • 24 Posts
  • 2 Reply Likes
Hi, as part of this discussion, is there any news on local notifications (thread here: http://community.phonegap.com/nitobi/...) - as it seems odd to me to have support for push notifications, but then to be missing one of the primary ways to update users as to the presence of new content, etc?
Photo of Vitaliy Radovanski

Vitaliy Radovanski

  • 12 Posts
  • 0 Reply Likes
Mark, I had a similar issue and found a solution at QuickBlox guidelines. Hope that helps.
Photo of Anton Suprunov

Anton Suprunov

  • 6 Posts
  • 0 Reply Likes
does anyone has same issue with iOS8: notifications confirmation popup appears on app start even if push plugin is not yet registered?
Photo of Phonegap

Phonegap

  • 3 Posts
  • 0 Reply Likes
From past one month looking our for the best source where I can learn much more about Phonegap and I get this link -- > http://www.brotsky.tv/2013/12/07/phon...

This is the best source for learning
Photo of Joan Patience

Joan Patience

  • 12 Posts
  • 3 Reply Likes
Use PushBots

I followed the guidelines here : https://pushbots.com/developer/docs/p...

And was up and running with in no time.

They also have good support.
Photo of Cristopher Parrela

Cristopher Parrela

  • 0 Posts
  • 0 Reply Likes
Photo of vinayak

vinayak

  • 9 Posts
  • 0 Reply Likes
how to pass data using phonegap
Photo of vinayak

vinayak

  • 9 Posts
  • 0 Reply Likes
how to insert data in mysql database in phonegap
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You already asked the same thing a while ago as an off-topic question in another thread. And....you even received replies.

Now, you're doing the same thing. Why?
Have you tried the given suggestions?