我想在我的应用中为用户添加设备令牌。我有设备令牌,我有用户,但我不能将令牌添加到用户,尽管阅读了大量有关该问题的文档。
任何人都可以帮助我吗?
这是我的代码,谢谢
var io = Ionic.io();
username = localStorage.getItem('username');
var signupSuccess = function(user) {
// user was authenticated, you can get the authenticated user
console.log(user);
};
var signupFailure = function(errors) {
for (var err in errors) {
// check the error and provide an appropriate message
// for your application
console.log(err);
user = Ionic.User.current();
console.log(user);
}
};
var details = {
'email': 'email@gmail.com',
'password': 'pass2',
'username':'username'
}
Ionic.Auth.signup(details).then(signupSuccess, signupFailure);
var push = new Ionic.Push();
var user = Ionic.User.current();
console.log('USER',user);
var callback = function(pushToken) {
console.log('Registered tokens:', pushToken.token);
alert('TOKEN: '+pushToken.token);
user.addPushToken(pushToken);
user.save(); // you NEED to call a save after you add the token
}
push.register(callback);