I am trying to get my notifications to work however I am not receiving them. I followed the tutorial for implementing pushwoosh on phonegap build. I have my App ID and API Key from Google however I am not getting my device which the app is on to register when I reinstall the app.
I am guessing that my issue is in the following code:
// handle GCM notifications for 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.
PushWoosh.appCode = "YOUR_PUSHWOOSH_APP_ID"; // my pushwoosh id is here
PushWoosh.register(e.regid, function(data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function(errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
break;
I inserted this code in <script> tags within my index file however the device doesn't register what could be causing this issue?
I should also mention that I have the pushwoosh.js file within my javascript folder and I am pointing to it in my reference tags for .js files
Related
I am a newbie on parse server and have been using it with my android app. But I am having trouble with implementing push notifications. I do not know how to get logs so any guidance will be much appreciated! The installation class does not contain any "GCMSenderId" or "deviceToken".
Here is how I set up parse server to implement push notifications.
Parse Sever : 2.2.7
1) Developer Console
a) I create a new project using the new console and clicked on the overflow menu --> Project Info and got my project number.
b) Then I went to the "Credentials" page and clicked on Create Credentials --> Api Key --> Server Key and left everything default and clicked create.
c) I got the key for my project. Let it be "MY_API_KEY".
2) Now I setup my parse server app to use this api key and project number as you can see from the image.
enter image description here
3) Now I setup my android app manifest accordingly as you can see from the picture below.
enter image description here
I also added ParseInstallation.getCurrentInstallation.saveInBackground();in my app's Application class.
I am trying to send notifications using the parse dashboard
Please provide any help if possible, thanks!
to send push notification from parse server you have to implement cloud code
in Javascript or another programming language.
below is some code in JS to send push notification to a user
function(objectids,msg) {
var pushQuery = new Parse.Query(Parse.Installation);
msg.default="default";
pushQuery.exists("deviceToken");
pushQuery.containedIn('userObjectId',objectids);
try
{
Parse.Push.send({
where: pushQuery,
data: {
alert:msg.msgInfo,
str:msg,
sound:msg.default
}
}).then(function() {
console.log("push successfully sent");
}, function(error) {
console.log("error while send pn:"+error.code+":"+error.message);
throw "Push Error " + error.code + " : " + error.message;
});
}catch(error)
{
console.log("error while send pn:"+error.code+":"+error.message);
}
}
Hi I follow the steps below
1) I created the cordova project structure.
2) I added the platform( android).
3) I added the cordova plugin
cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0
4) Bulid the cordova project.
5) Next I import the created app in android eclipse(4.4.2)
6) I wrote the code below in index.js file
init: function(){
alert("init");
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler,
{
'senderID':'XXXXXXXXXX',
'ecb':'onNotificationGCM' // callback function
}
);
function successHandler(result) {
console.log('Success: '+ result);
alert(result);
}
function errorHandler(error) {
console.log('Error: '+ error);
}
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
}
else if('error' === e.event) {
// Failed to register device.
}
};
I am getting the respose as "OK".and i am not able call 'ecb': onNotificationGCM' // callback function
In Android console I am getting the bellow Message
V/PushPlugin(2512): execute: action=register
V/PushPlugin(2512): execute: data= [{"senderID":"889953963751","ecb":"onNotificationGCM"}] V/PushPlugin(2512): execute: jo={"senderID":"889953963751","ecb":"onNotificationGCM"} V/PushPlugin(2512): execute: ECB=onNotificationGCM senderID=889953963751
09-12 03:13:33.453: D/GCMRegistrar(2512): resetting backoff for com.ensis.hello
09-12 03:13:33.613: V/GCMRegistrar(2512): Registering app com.ensis.hello of senders 889953963751
09-12 W/PluginManager(2512): THREAD WARNING: exec() call to PushPlugin.register blocked the main thread for 181ms. Plugin should use CordovaInterface.getThreadPool().
This is the push notification flow:
your app request a registration to the remote Apple or Google server
if the registration is ok, the remove server returns a token, that identify this specific app on your device
you send this token to your server, saving it (e.g. on a db)
you send a push notification (from your server) calling Apple or Google services with the message and the tokens of the users you want to notify
these services push to your device/app a notification with the message
You must follow all these steps in order to have push notification working.
For android you need to catch the registration id (token) inside the registered event of the notification handler:
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
console.log("regID = " + e.regid);
// save/send this registration id on your server
} else if('error' === e.event) {
// Failed to register device.
}
};
For iOS you need to catch it in the succesHandler of the register function.
For more information look at this example in the plugin repository.
I am implementing android push notification. I could create the cordova/phonegap app using Intel XDK and made all the setup on GCM. I can see my application showing the registration id when I install the app and story is smooth till this.
Now I want to send the registration id to my application server that I hosted. I have already written the rest api which can receive a get and save the registration id. Now the issue is when ever I add the Restful call in onNotificationGCM of index.js, the apk installation shows error "There was problem parsing the package". Please find my onNotificationGCM call code
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
var req = new XMLHttpRequest();
var url = "http://XXXX.com/mycloudapp/register?regid="+e.regid;
console.log("Regid " +url);
req.open("GET", url, true);
console.log("After req.open");
req.send();
console.log("after send");
alert('registration id = '+e.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
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;
}
}
if I remove the below code from above, again it works fine
req.open("GET", url, true);
console.log("After req.open");
req.send();
Your help is highly appreciated!!!!
At last I could solve the issue. The issue is nothing to do with the coding, but Intel XDK project configuration for white listing the external domain. Please follow steps below
1) Select you project
2) Go to the Build Settings and expand
3)Goto Access List box
4) Keep * and select External
5) Add Another access list entry
6) Provide the external domain URL select internal
This worked for me very well.
For a while now, I have been trying to figure out how to send push notifications. The app I have made is for Android right now, but I want to extend it to other devices once I figure this out. I've looked into various services, such as Amazon SNS, but they all neglect to include how to get the device token. They all assume you know how to do that.
So what I am asking is: how do I get a device token/registration ID for a device?
I tried using this code:
var tokenID = "";
document.addEventListener("deviceready", function(){
//Unregister the previous token because it might have become invalid. Unregister everytime app is started.
window.plugins.pushNotification.unregister(successHandler, errorHandler);
if(intel.xdk.device.platform == "Android")
{
//register the user and get token
window.plugins.pushNotification.register(
successHandler,
errorHandler,
{
//senderID is the project ID
"senderID":"",
//callback function that is executed when phone recieves a notification for this app
"ecb":"onNotification"
});
}
else if(intel.xdk.device.platform == "iOS")
{
//register the user and get token
window.plugins.pushNotification.register(
tokenHandler,
errorHandler,
{
//allow application to change badge number
"badge":"true",
//allow application to play notification sound
"sound":"true",
//register callback
"alert":"true",
//callback function name
"ecb":"onNotificationAPN"
});
}
}, false);
//app given permission to receive and display push messages in Android.
function successHandler (result) {
alert('result = ' + result);
}
//app denied permission to receive and display push messages in Android.
function errorHandler (error) {
alert('error = ' + error);
}
//App given permission to receive and display push messages in iOS
function tokenHandler (result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send the token to your server along with user credentials.
alert('device token = ' + result);
tokenID = result;
}
//fired when token is generated, message is received or an error occured.
function onNotification(e)
{
switch( e.event )
{
//app is registered to receive notification
case 'registered':
if(e.regid.length > 0)
{
// Your Android push server needs to know the token before it can push to this device
// here is where you might want to send the token to your server along with user credentials.
alert('registration id = '+e.regid);
tokenID = e.regid;
}
break;
case 'message':
//Do something with the push message. This function is fired when push message is received or if user clicks on the tile.
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;
}
}
//callback fired when notification received in iOS
function onNotificationAPN (event)
{
if ( event.alert )
{
//do something with the push message. This function is fired when push message is received or if user clicks on the tile.
alert(event.alert);
}
if ( event.sound )
{
//play notification sound. Ignore when app is in foreground.
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
//change app icon badge number. If app is in foreground ignore it.
window.plugins.pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
All I get is an alert that says "result = ok". The alerts later on in the code don't happen. I've tried making sense of the code but I'm not getting anywhere. Any suggestions? Is there a tutorial for this I'm not finding?
Those legacy intel.xdk functions are being retired (the will continue to live in an 01.org, see the notice on this page: https://software.intel.com/en-us/node/492826).
I recommend you investigate one of the many push notification Cordova plugins that are available. Use your favorite web search tool to search for something like "cordova phonegap push notification plugin" to find some. The good ones will have examples of how to use.
Note:-
Unregister - Its not strictly necessary to call it.....
Ensure that you have a sender ID for Android (no idea about iOS).
Result OK means that the plugin is installed correctly and has run properly.
Problems could be due to:
Incorrect sender ID
Testing in emulator without adequate setup
Important - Push notifications are intended for real devices. They are not tested for WP8 Emulator. The registration process will fail on the iOS simulator. Notifications can be made to work on the Android Emulator, however doing so requires installation of some helper libraries, as outlined here, under the section titled "Installing helper libraries and setting up the Emulator".
onNotification must be available as a global object. So try attaching it to the window. Refer to this question
Examples of properly initializing PushPlugin in:
Ionic (my answer)
I'm trying to send push notifications to my Android device from my server. Using plug PushNotification Cordova, my code is something.
var androidConfig = {
"senderID": "inspired-berm-101218",
};
document.addEventListener("deviceready", function(){
$cordovaPush.register(androidConfig).then(function(result) {
// Success
}, function(err) {
// Error
})
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
alert('registration ID = ' + notification.regid);
sessionService.set("token_device",notification.regid);
My information according to me, I followed advice from this forum and tutorials are good and are these:
Api KEY : AIzaSyDtZndyGvmWXF0TpYe83KVDgxRZ4MR3zK8
ID del proyecto: inspired-berm-101218
NĂºmero del proyecto: 805573676421
All this I use both my application and server are the same codes, but nevertheless, I receive the error:
{"multicast_id":7843752850335107662,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
Try uninstalling the application on my phone and reinstall but nothing, does not this work for me.
Use this website to create and run the application again immediately, it gives the exact data.
Google Developers