phonegap / phonegap-plugin-push Goto Github PK
View Code? Open in Web Editor NEWRegister and receive push notifications
License: MIT License
Register and receive push notifications
License: MIT License
Android sets additionalData.foreground: true
on notification data when the app is open. This is helpful because background notifications - in most apps - when tapped will go to a route... but if the app is open we will likely alert the user in a different manner instead of route them away from where they are.
Is this not 100% necessary for iOS too? Maybe i'm missing another way to achieve the same thing?
Hi, i'm creating an app and I'm testing its on iPad with iOS 8 and iPhone with iOS 9. When i accept push notification in iOS 9 sound is not active, infant in push notification setting on iPhone there isn't sound option yes/no for my app, for other app yes. On iPad with iOS 8 sound option there are and i receive sound. Today i update iPad to iOS 9 and sound option disappear so i can't receive sound also on iPad. At this point i think that the problem is with plugin and iOS 9. I hope that someone can help me and all other developer that use this plugin because approximately on 15 settembre iOS 9 became public for everybody.
Thanks
I've tried the code below on two different iPhone running iOS 8.4 and the error callback is always called twice, with the value being constantly {}
.
The code runs after deviceready
is fired, and works fine on Android.
var plugin = PushNotification.init({ "android": {"senderID": "XX"},
"ios": {'badge': true, 'sound': true, 'alert': true}});
plugin.on('registration', function (data) {
alert("Registration: " + JSON.stringify(data));
});
plugin.on('notification', function (data) {
alert("Notification: " + JSON.stringify(data));
});
plugin.on('error', function (e) {
alert("Error: " + JSON.stringify(e));
});
Any idea what could possibly be wrong?
When a PG/Cordova-App is closed and started upon user's activating the PushMessage, this message is not forwarded to Host-App.
It seems that plugin (PushPlugin.m) receives message and only afterwards comes registration from Host-App. So probably because there are still no callbacks registered message gets lost.
In my app PushNotification.init is called on cordova's onDeviceReady event.
The guys from https://github.com/Telerik-Verified-Plugins/PushNotification seem to handle the problem well. The scenario works on their code.
I am sending 3 pushes with different notId and when my app is in foreground it receives all 3 pushes, but when it is running in background or it is closed, I receive the 3 pushes on the notification bar, but when I click one of the pushes it gets the app opened and shows the message from the push, but the other 2 messages disappear from the notification bar.
Hi,
I have code that adds the following functionality (as of now just on android):
Upon a GCM with REPORT_LOCATION in a certain field, the client sends its current location via http request to a predetermined endpoint (without bothering the user).
(It can't be done from javascript because the app is not always active)
This is useful when the server needs accurate client location in a specific time, but periodically updating the server costs precious battery.
Does this sound like something you'd like to incorporate?
Is this plugin currently up and and working?
Hi. Using almost the same code in example e got an error message saying that. I got this errro puting a Try before "var push".
The code:
"""
try{
var push = PushNotification.init({
"android": { "senderID": "xxxxx" }
});
}catch(err){
alert("Error: " + err.message);
}
"""
In config XML I've add the lines:
"""
feature name="PushNotification"
param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/
/feature
"""
I'm doing something wrong? Thanks.
It does say it registered successfully in console but the event isn't triggering for some reason?
Any ideas?
symbol: method setColor(int)
location: variable mBuilder of type Builder
Still refers to old package name
On the PushPlugin, i.e. https://github.com/phonegap-build/PushPlugin, I had a really strange issue on Android Phones. iOS does not have this issue, android does. The issue is as follows:
I used to call the register() function to register with GCM.
var pageHome = {
pushNotification: window.plugins.pushNotification,
initPush: function() {
pageHome.pushNotification.register(pageHome.successHandler, pageHome.errorHandler, {
"senderID" : "1234567890",
"ecb" : "pageHome.onNotificationGCM"
});
},
onNotificationGCM: function(e) {
switch(e.event) {
case 'registered':
// Just a random check for the regid.
if (e.regid.length > 0) {
// Get the pushToken from localStorage.
var pushToken = localStorage.getItem("pushToken");
// Check if the registration has already happened and whether the already stored pushToken is the same as the new registration id (e.regid) coming as a result of re-registration with the GCM server
if(pushToken == null || pushToken != e.regid) {
// If the device has NOT registered or the device id has changed then only register again.
$.ajax({
url: 'https://xyz.com/register',
type: 'POST',
dataType: 'json',
data: {regId : e.regid},
success: function(data) {
// If stored on my own server, then only save it to localStorage.
localStorage.setItem("pushToken", e.regid);
},
error: function(error) {
}
});
}
}
break;
case 'message':
navigator.notification.alert(e.payload.message, app.alertDismissed, e.payload.title, 'Dismiss');
break;
}
}
}
The problem I have been facing for long is that more than one android device has the same registration id. I mean the registration id is not unique for different devices. Multiple devices have the same registration id. This is quite weird and I have been facing this issue with that plugin. Will this plugin solve this error? Or is this error due to Google GCM servers? In all my apps I have this issue..
There's no way to update the app icon badge number, like in the previous version with setApplicationIconBadgeNumber?
Hi, im trying to register a device trough the register method, following your example, but when i call it, the Xcode logs only shows "Push Plugin register called" but no "Push Plugin register success". Cant get the iOS token and complete a successfully register process. Im trying with and iPAD with iOS 8.1.1 and Xcode 6.3.1
if u could help would be great ;)
Sending a push notification only calls on('notification') once, while the app is in the foreground.
To reproduce:
on('notification')
callbackPush Plugin key: alert
etcon('notification')
callback is fired and outputs to logPush Plugin key: alert
etcImmediately after our application starts, the iOS window "X would like to send you push notifications", yet before the init
method of the push plugin is called.
We would like to defer the initial demand to be aligned with the call to init
so that users are not immediately asked if they want to receive push notifications (research shows that people are less inclined to accept if they don't know what it is for, e.g. http://techcrunch.com/2014/04/04/the-right-way-to-ask-users-for-ios-permissions/)
Not sure to exactly understand how everything is happening in AppDelegate
, any idea on this?
Hi, this is a follow-up issue to #54.
I'm using the plugin on a android device:
var push = PushNotification.init({
"android": { "senderID": "123456789" },
"ios": {}, "windows": {}
});
push.on('registration', function (data) {
alert("Token: " + data.registrationId);
});
push.on('error', function (e) {
alert("Error: " + e.message);
});
When the device sucessfully gets a token for GCM, everything works and the alert is shown.
However when the device cannot get the token, the "error" event on the push object is not raised, so no alert is shown.
When a error occurs, the android logs show this:
D/GCMBaseIntentService( 1895): handleRegistration: registrationId = null, error = AUTHENTICATION_FAILED, unregistered = null
D/GCMBaseIntentService( 1895): Registration error: AUTHENTICATION_FAILED
E/PushPlugin_GCMIntentService( 1895): onError - errorId: AUTHENTICATION_FAILED
GCMIntentService.onError() is called, but this method only has a logging statement, so the implementation to delegate the error to the javascript push.error event seems to be missing:
@Override
public void onError(Context context, String errorId) {
Log.e(LOG_TAG, "onError - errorId: " + errorId);
}
Thanks!
Hi,
I have this switch that lets you "unregister" your device. However, when switched by mistake, switching it back should bring op the "Allow push notifications" alert again. There's no way to do that now.
I'd like to see a "register" function added, so I can register a device programmatically
Hi, this version on push plugin is very different from the previous one. It would be nice to see examples of working with notifications, for example behavior depending of the platform, when the app is in background and foreground, etc
Hi,
I found this plugin when searching for a successor of the PushPlugin (https://github.com/phonegap-build/PushPlugin) which seems not to be developed further.
The current readme says that support for "WP8" is under development. However it does not say about the Win 8.1/WP 8.1 (Universal Apps) platform.
As this seems to be a new plugin, what about dropping support for WP 8.0 and instead only supporting Win 8/8.1/WP 8.1 "Universal Apps"? Note that these platforms will use WNS (Windows Notification Service) instead of MPNS (Microsoft Push Notification Service) that was used in WP 8.0 (Note that the Cordova Device Plugin reports an Universal App on WP 8.1 as "windows".
Note that the old PushPlugin (https://github.com/phonegap-build/PushPlugin) does not work on Win 8.1/WP 8.1 in the current Cordova version shipped with VS 2015 RC as it specifies a wrong include file, but I found a fork that fixes this issue: https://github.com/kenwu27/PushPlugin (it worked for me on a Windows Phone 8.1 emulator included in Visual Studio 2015 RC, using a Cordova App).
So you could implement support for Push Notifications on Win 8/8.1/WP 8.1 using WNS based on that implementation.
Thanks!
Hi,
I'm using this plugin in a Cordova App (using Cordova 5.1.1, android-minSdkVersion=15, android-targetSdkVersion=22) in Visual Studio 2015 to send push notifications with a server. WNS and APNS work without a problem, but I coulnd't get GCM on Android to work. I tested it on an Android 4.0.4 and on an Android 5.1 device.
After debugging the plugin, I found that it seems to use the wrong message keys.
My scenario is the following:
"notification"
event handler to verify that a notification has been received (I have obscured IDs etc. in the sample code): function onDeviceReady() {
// Register for notifications.
var push = PushNotification.init({
"android": { "senderID": "xxxxx" },
"ios": {}, "windows": {}
});
push.on('registration', function (data) {
// Send data.registrationId to the server...
});
push.on('notification', function (data) {
alert("Notification: " + data.message)
});
};
The "registration"
event handler is successfully called and the registration ID is sent to the server. Some time later the server sends a JSON message to the Google GCM service (https://gcm-http.googleapis.com/gcm/send):
{
"registration_ids": [
"APA91bHxxxxxxxxxxxxxxxxxx"
],
"notification": {
"title": "Hi",
"message": "Hi, this is a Test"
}
}
GCM then responds with the following JSON:
{
"multicast_id": xxxxxxxxxx,
"success": 1,
"failure": 0,
"canonical_ids": 1,
"results": [
{
"registration_id": "APA91bFakxxxxxxxxxx",
"message_id": "0:xxxxxxxxxxxxxx"
}
]
}
So, GCM sucessfully received the message. However no notifications did show on android when the app was in the background, and when it was in the foreground the alert also did not apper.
I then inserted some debug statements in the GCMIntentService.java file and found that it seems to use the wrong keys for GCM message.
private void onMessage(...) contains the following code:
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
So it checks for a "message"
key. However, after printing extras.toString()
, I got the following:
Bundle[{gcm.notification.message=Hi, this is a Test, gcm.notification.title=Hi, collapse_key=do_not_collapse, from=xxxxxxxxxx}]
So, actually the keys are "gcm.notification.message"
instead of "message"
and "gcm.notification.title"
instead of "title"
. After I replaced extras.getString("message")
with extras.getString("gcm.notification.message")
etc. in this class and in the PushPlugin class, everything worked - the phone showed the notification in the notification bar.
Any idea why the notification payload fields in the bundle contain the prefix "gcm.notification."
which the plugin does not check? I haven't found a similar report though.
Also it seems strange to me that the plugin expects the message text in a "message"
field, whereas the GCM Server Reference (https://developers.google.com/cloud-messaging/server-ref#notification-payload-support) specifies that the text should be in a "body"
field in the notification payload.
Thanks!
Currently, notifications won't stacked in the notification panel, so old notifications replaced by new one. I think "notId" option worth mentioning in the documentation. However, in my point of view stacking notifications is a better approach.
hi @macdonst
I am using PGB 3.7.1 (build.phonegap.com)
I know your plugin have no wp8 version for now
but it will Indirectly cause wp8 platform build fail
see my screenshot
Hi,
My users ask me an option to silence (no sound nor vibrate) notifications for the next X hours (for example by night or because of a meeting). The notifications should be back to normal (sound + vibrate) after the time limit expire without the user launching the app.
Would it be possible to control sound/vibrate for each notification sent? With params vibrate/silence sent to gcm/apns?
Thanks by advance
Hi,
currently, there is an error in the documentation:
var push = PushNotification.init({ "android": {"senderId": "12345679"},
"ios": {}, "wp": {"channelName": "12345679"} } );
which cause "No value for senderID" error.
Correction: senderId => senderID
When there are more than one notification in status bar (different notIds), tapping on any of then will open the last received (Android only).
Nitpicking but I think that directory should be lowercase to match the file structure :)
Line up with Windows implementation
I'll slack ya about this
The plugin stopped playing notification sounds after I've updated to version 1.1.1 (I’m not passing custom sound file name in the payload).
Maybe the reason is because of the following commented line in GCMIntentService.java bellow:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
//.setDefaults(defaults)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);
Hi friends,
I am trying to implement is:
When user receives a push notification, I want to make a ajax to server to get additional data for that notification, save them in local database, to display updated info to user when he opens app even when he is offline(later).
Now the issue is:
Notification received event (JavaScript function: push.on('notification', function(data) {});) is invoked only when
- User click on notification from notification bar
- App is open
If app is closed/in background, & user don't click notification from notification bar, the notification receive event (push.on('notification', function(data){};) is not called.
What I need is:
I need JavaScript function be invoked at the same time notification is received regardless of app status (foreground/background/closed) and regardless of user clicks notification.
P.S. I am currently implementing in Android
Thanks
Greetings - Thank you @macdonst for all of your work with PhoneGap. We currently use your videoplayer plugin for Powerline. Good stuff!
Anyway, we are looking for the ability to add buttons to a notification similar to how GMail allows you to View or Reply to an e-mail when you're looking at the preview in the OS notification drawer (see image below). Your Push plugin has all the other features we're looking for (remote loaded large icon, small icon overlay, title, message, sound, badge, etc.), but it doesn't have multi-line text support (again, think previewing a gmail message) or this button concept.
Is that on your roadmap at all? Do you know if anyone is currently working on that? Hope this is the right place for this question!
Thanks,
Jesse
it seem no wp8 version for now
according to this
https://github.com/phonegap/phonegap-plugin-push/tree/master/src
no wp8 folder too
but the previous pushplugin have this one
https://github.com/phonegap-build/PushPlugin/tree/master/src
so...just want to know
why this new version abandon this ?
according to the "Quick Example"
https://github.com/phonegap/phonegap-plugin-push
I test in Android 4.4.2 and iOS 8.4 that all in real device
when in android,the "registration" behavior only trigger one time
but...
when in ios,the "registration" behavior will trigger twice times
Hi,
Sorry, this is not an issue, i'd just like to know if there is a way to programmatically mute notifications for the app?
Thanks
Hi,
i just found a usability issue.
If the User is exiting the App and getting a Push afterwards, the PushPlugin is still registering the Push but is not returning the Data to the App.
Aug 5 09:04:04 Tims-iPhone6 OK[7443] : Notification received
Aug 5 09:04:04 Tims-iPhone6 OK[7443] : Push Plugin key: alert
Aug 5 09:04:04 Tims-iPhone6 OK[7443] : Invalid callback id received by sendPluginResult
It would be great, to read PushData received after the initalization of the App.
Thanks for your work on this plugin! :)
Best,
Tim
Why I can't the app play a custom sound with the notification when is in background? I'm sending the sound name in the notification...I neither can make this to work in the previous version of the plugin.
I have beep.wav in my www folder. For Android I'm sending 'soundname': 'beep.wav' in the payload, and 'sound': 'beep.wav' for iOS
My code:
App:
var push = PushNotification.init({
"android": {
"senderID": "..."//I put here my GCM senrder id
},
"ios": {}
});
push.on('registration', function(data) {
// data.registrationId
registerNotificationToken(data.registrationId, (window.device.platform == 'android' || device.platform == 'Android') ? 'Android' : 'iOS');
});
push.on('notification', function(data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.additionalData
if (isLogedIn()) {
if (window.device.platform == 'android' || device.platform == 'Android') {
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( data.additionalData.foreground )
{
var my_media = new Media("/android_asset/www/" + data.sound);
my_media.play();
alertify.confirm('<p><strong>' + data.title + '</strong><p/><p>' + data.message + '</p><p>¿Desea verlo?</p>', function () {
location.hash = 'available-services\\' + data.additionalData.id;
});
}
// otherwise we were launched because the user touched a notification in the notification tray.
else {
//If app wasn't runing
if ( e.coldstart ) {
serviceId = data.additionalData.id;
}
else {
location.hash = 'available-services\\' + data.additionalData.id;
}
}
}
else {
if ( data.additionalData.alert ) {
//do something with the push message. This function is fired when push message is received or if user clicks on the tile.
if (data.additionalData.foreground == 1) {
alertify.confirm('<p><strong>' + data.title+ '</strong><p/><p>' + data.message + '</p><p>¿Desea verlo?</p>', function () {
location.hash = 'available-services\\' + data.additionalData.id;
});
}
else {
location.hash = 'available-services\\' + data.additionalData.id;
}
}
if ( data.sound ) {
//play notification sound. Ignore when app is in foreground.
var snd = new Media(data.sound);
snd.play();
}
}
}
Hi!
How?:)
Looking for the ability to display up to some arbitrary number of multi-line text when previewing from the notification drawer. It looks like gmail has support for at least 3 "lines" of text so we can start there as a base point. however, I'm not sure if this is based on buffer size or a limit on number of characters but either would work just fine here.
This is a follow up to issue 62
Custom payloads that are siblings of aps
are allowed by Apple and should be added to message.additionalData. Now only children of aps
are allowed.
do i need to call PushNotification.init every time that app is opening ?
it seems init method will register GCM token every time
When using unregister, all switches are still on in the notification settings of iOS
This happen when I try to remove the plugin from my app (I think you miss to rename some things, the cli is looking at com.phonegap.plugins.PushPlugin, when the plugin folder is called phonegap-plugin-push)
E:\LocalDocs\Iridian\PilotoAutomatico\PilotoAutomaticoConductoresCLI>cordova plu
gin rm phonegap-plugin-push
Uninstalling phonegap-plugin-push from android
Removing "phonegap-plugin-push"
Error: ENOENT, no such file or directory 'E:\LocalDocs\Iridian\PilotoAutomatico
PilotoAutomaticoConductoresCLI\plugins\com.phonegap.plugins.PushPlugin\plugin.xm
l'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.readFileSync (fs.js:289:15)
at Object.module.exports.parseElementtreeSync (C:\Users\DELL\AppData\Roaming
\npm\node_modules\cordova\node_modules\cordova-lib\src\util\xml-helpers.js:118:2
7)
at new PluginInfo (C:\Users\DELL\AppData\Roaming\npm\node_modules\cordova\no
de_modules\cordova-lib\src\PluginInfo.js:320:37)
at PluginInfoProvider.get (C:\Users\DELL\AppData\Roaming\npm\node_modules\co
rdova\node_modules\cordova-lib\src\PluginInfoProvider.js:35:32)
at C:\Users\DELL\AppData\Roaming\npm\node_modules\cordova\node_modules\cordo
va-lib\src\plugman\util\dependencies.js:42:49
at Array.forEach (native)
at Object.module.exports.package.generateDependencyInfo (C:\Users\DELL\AppDa
ta\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\util\de
pendencies.js:38:45)
at C:\Users\DELL\AppData\Roaming\npm\node_modules\cordova\node_modules\cordo
va-lib\src\plugman\uninstall.js:166:37
at Array.forEach (native)
Updated the init method to pass in a vibration parameter.
Hello,
I'm developing an iOS app and the notifications appear on the device regularly, problem is the application badge doesn't appear, despite it being in the notification payload. Logging in the lldb console reveals that the function never gets called when in background.
Do I need to set any flag or move the plugin outside the device ready event?
I'm running iOS 7.1 on an iPhone 4.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.