javascript - ionic 推送 IO : no device token in 'users' assigned to user

标签 javascript android ionic-framework google-cloud-messaging

我一直在尝试使用 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);

我的 ionic 界面是这样的: enter image description here

我实际上希望我的设备 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/

相关文章:

javascript - 无法在新选项卡中打开 pdf 文件

javascript - 如何使用javascript获取列表项中的第一个和最后一个元素

android - 如何在android中以编程方式控制横向和纵向?

android - 什么时候应该使用 Theme.AppCompat 与 ThemeOverlay.AppCompat?

android - 请求好友列表时应用程序崩溃

mongodb - 按多个值过滤对象

javascript - 以 Angular 访问工厂回调函数内部的变量

javascript - 使用猫头鹰轮播时禁用触摸设备上的垂直滚动

javascript - Meteor Flow Router 嵌套动态模板

ionic-framework - 我们如何在 ionic 4 for IOS 中使用 chrome cast use?