【问题标题】:OnNotificationGCM is not called in ionicOnNotificationGCM 不在 ionic 中调用
【发布时间】:2015-09-16 14:05:50
【问题描述】:

this 帖子中我尝试了所有方法,但仍然没有获得注册ID。请有人帮我解决这个问题。

我可以在 Eclipse 的 logcat 中看到注册 ID,但它没有调用 onNotificationGCM 方法。

【问题讨论】:

    标签: android cordova push-notification ionic


    【解决方案1】:

    首先使用最新的推送插件。使用以下命令将插件安装到您的项目中:
    ionic plugin add phonegap-plugin-push
    要注册您的设备,请在您的 js 代码中使用此行,此行只会注册您的设备。

    var push = PushNotification.init({ "android": {"senderID": "your-sender-id"}} );
    

    现在您的设备已注册,并从 GCM 服务生成带有设备令牌的事件,您可以使用以下代码在您的应用程序中接收该事件

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

    就是这样。您不必使用旧插件,因为最新的插件更易于使用。这是link 最新插件的文档。

    【讨论】:

    • 你能告诉如何通过命令安装最新的推送插件吗?我正在使用cordova 8。如果我只输入ionic plugin add phonegap-plugin-push就足够了吗?还是我必须在 config.xml 中添加任何内容?
    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    相关资源
    最近更新 更多