Austin Hunter
Austin Hunter

Reputation: 394

Device Token Phonegap

Hello I am using ionic to write a hybrid app that will send push notifications. I have a question to setup the phonegap-plugin-push.

I am trying to get my device token and send it to my nodejs server.

I am using this plugin: https://github.com/phonegap/phonegap-plugin-push

Here is my current code:

var app = angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $rootScope, $window, $http) {
   $ionicPlatform.ready(function() {
       
  });
})

How can I get and store my device token using this plugin?

Upvotes: 0

Views: 726

Answers (1)

Ali Esmaeili
Ali Esmaeili

Reputation: 542

According to this example from phone-gap documents you should call this function on your device ready (also safer to use a 1 second delay for this function).

code :

var push = PushNotification.init({
android: {
    senderID: "12345679"
},
browser: {
    pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios: {
    alert: "true",
    badge: "true",
    sound: "true"
},
windows: {}
});

push.on('registration', function(data) {
    // data.registrationId
});

After that you should post the data.registrationId to server to keep it for sending notifications .

Upvotes: 2

Related Questions