我一直在尝试使用 Ionic 推送通知,一切都很顺利,直到我不得不存储收到的设备 token 。我一直在按照教程给我的每一步进行操作,所以我没有在我的项目中看到任何错误的代码。
这是我的注册码:
// kick off the platform web client
Ionic.io();
var push = new Ionic.Push();
// this will give you a fresh user or the previously saved 'current user'
var user = Ionic.User.current();
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
user.id = Ionic.User.anonymousId();
}
var callback = function (data) {
console.log('Registered token:', data.token); // is not empty
console.log(data.token);
push.addTokenToUser(user);
user.save();
}
push.register(callback);
我收到以下错误:
Ionic Push Token: dev tokens cannot be saved to a user as they are a temporary resource: ionic.io.bundle.min.js (2,5965).
当我尝试执行时:
push.addTokenToUser(user);
我实际上希望我的设备 token 存储在那里。但事实并非如此..
我希望你们中的一些人以前见过这个问题,也许能帮助我。
您好!
最佳答案
在我发现我使用的是旧版本的 cordova (v.4) 之前,我遇到了这个问题。低于 v.5 的任何内容都无法与 Ionic 一起正常工作(截至撰写本文时,当前的 Cordova 版本为 6.0.0)。
npm update -g cordova
之后一切都按照记录进行。
关于javascript - ionic 推送 IO : no device token in 'users' assigned to user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35556752/