【问题标题】:PushPlugin For PhoneGap Build Background NotificationsPhoneGap 的 PushPlugin 构建后台通知
【发布时间】:2014-04-05 19:05:04
【问题描述】:

我无法使用 PhoneGap Build 和 PushPlugin 在后台接收通知并显示在通知托盘中。我正在使用 Cordova 3.3 和最新版本的 PushPlugin。

应用打开时一切正常。我收到有效载荷并可以做出相应的响应。

当应用程序关闭或在后台运行时没有任何显示。我希望至少通知托盘中会出现警报,但我没有收到。

如何解决这里发生的问题?我知道我的插件使用基本正确,因为当应用程序在前台时它工作正常。

【问题讨论】:

  • 您的消息是否在数据对象中设置了 messagemsgcnt 属性?在后台收到时,它们是 android 的必备品。

标签: cordova push-notification phonegap-build phonegap-pushplugin


【解决方案1】:

对于安卓:

因为插件中的这段代码,出现在第 80 行附近的“GCMIntentService.java”中:

// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
    createNotification(context, extras);
}

为了能够使用 GCM 接收后台通知,来自服务器的消息结构应如下所示:

{"message":"Hello World", "title":"Title", "msgcnt":1, "soundname":"sound.mp3"}

并且必须有“消息”属性!

【讨论】:

    【解决方案2】:

    我为 iOS 解决这个问题的方式。

    应用中的 pushplugin 将解析和处理这样的消息:

    {"alert":"Hello from APNs Tester.","badge":"1"}

    然而,iOS 只会处理具有正确结构的消息

    {"aps":{"alert":"Hello from APNs Tester.","badge":"1"}}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多