I am using ionic to develop an application and I need to get the device token for push notifications, but having trouble. The application isn't receiving notifications, but I still need to send device token when user login into the application (e.g. I need to get device token without receiving notifications). I tried using the Cordova push notification plugin also.
-
Where is the code you have tried. and why you have pasted the exact thing three times?M. Junaid Salaat– M. Junaid Salaat2016-04-19 12:30:55 +00:00Commented Apr 19, 2016 at 12:30
-
thank you for correction mJunaidSalaatManoj Rejinthala– Manoj Rejinthala2016-04-19 13:33:17 +00:00Commented Apr 19, 2016 at 13:33
-
I don't have any notification yet just i need to send device token when user login into the application that sit.i need to get device token with out any notificationManoj Rejinthala– Manoj Rejinthala2016-04-20 04:12:38 +00:00Commented Apr 20, 2016 at 4:12
2 Answers
I've used phonegap-plugin-push plugin and its pretty easy and simple. For regID in the code on deviceReady event I've used.
var push = PushNotification.init({
"android": {
"senderID": "SENDER-ID"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
console.log("registration event");
//here is your registration id
console.log(data.registrationId);
});
This is the link of the tutorial too
Hope it helps.
7 Comments
Here is the ng-Cordova document which is for getting current device token id.
copy and past it in your project controller.
In the given below line you can find notification parameter
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification)
The notification is an object and it will have an regid field which provides you the current mobile device id you can make use of that like (posting to server, view in console.log(notification);)
To send the device token to you server you need just do
var loginPost = {
"UserName":"Mike",
"PassWord":"xxxxxx",
"DeviceID":notification.regid
};
Using this loginPost variable object post to the server.