Removing a device marker from a device using an ionic framework

I use ionic to develop the application, and I need to get the device token for push notifications, but with a problem. The application does not receive notifications, but I still need to send the device token when the user enters the application (for example, I need to get the device token without receiving notifications). I also tried using the Cordova delivery notification plugin.

+5
source share
4 answers

use the plugin below to get the device token value. ion plugin adds phone saver-plugin -variable SENDER_ID = "GCM_PROJECT_NUMBER"

use the code below to get the device token value.

 .run(function($ionicPlatform) { $ionicPlatform.ready(function() { push = PushNotification.init({ android: { senderID: "61426985247", sound: "true", vibrate: "true", forceShow: "true" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, ios: { alert: "true", badge: true, sound: 'false' }, windows: {} }); push.on('registration', function(data) { alert("device token" + data.registrationId); }); }); }) 
-1
source

I used the phonegap-plugin-push plugin and its quite easy and simple. For regID in code on the deviceReady event I 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 a tutorial link.

Hope this helps.

+5
source

Here is the ng-Cordova document, which is designed to get the current device token identifier.

copy and skip it in your project controller.

In the line below you can find the notification parameter

 $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) 

A notification is an object, and it will have a regid field that provides you with the current identifier of the mobile device that you can use, for example (sending to the server, viewing in console.log (notification);)

To send the device token to the server, you just need

 var loginPost = { "UserName":"Mike", "PassWord":"xxxxxx", "DeviceID":notification.regid }; 

Using this entry, the variable loginPost to the server.

+1
source

to get a token you need this plugin

-3
source

Source: https://habr.com/ru/post/1247426/


All Articles