简体   繁体   中英

How would I collect the device token in my Ionic/Cordova app

I am using Ionic with Ionic Push for push notifications (all works so far).

Part of my mobile app will send a request and somehow programmatically add the token from that device, can anyone explain how I grab the token using my code below?

var io = Ionic.io();

var push = new Ionic.Push({ });
var user = Ionic.User.current();

if (!user.id) {
  user.id = Ionic.User.anonymousId();
}

user.set('name', 'Bob');
user.save();

var callback = function() {
  push.addTokenToUser(user);
  user.save();
};

push.register(callback);

This worked in the end, it might help others

var callback = function(data) {
   var token = data.token;
   alert('my token: '+ token);
   push.addTokenToUser(user);
   user.save();
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM