使用 PushPlugin 插件,Phonegap 推送通知不会出现在 iOS 的状态栏和锁定屏幕中

Phonegap push notification does not appear in Status bar nor in Lock screen for iOS using the PushPlugin plugin

简介

我正在使用 Phonegap 4.2(基于 Cordova 5.0)创建跨平台应用程序。

对于 iOS,我正在使用 Xcode 6.0 并且我正在使用 PushPlugin Cordova 插件来处理推送通知。

我的问题

我可以在 iOS 版本的应用程序中接收推送通知,但是 当应用程序 运行然后我没有收到任何推送通知 并且它们不会出现在状态栏或锁定屏幕中。 background 我的意思是当应用程序关闭时。

详情

引用

我在 config.xml 中正确包含了 PushPlugin 插件:

<feature name="PushPlugin">
    <param name="android-package" value="com.plugin.gcm.PushPlugin" />
    <param name="ios-package" value="PushPlugin" />
</feature>

我在 index.html 文件中正确引用了 PushPlugin JavaScript 对象:

<script type="text/javascript" src="./js/PushNotification.js"></script>

附加推送通知事件

我已将通知事件正确附加到方法 onNotificationAPN:

pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos')
{
    // ...
}
else
{
    pushNotification.register(tokenHandler, errorHandler, 
    {
        "badge":"true",
        "sound":"true",
        "alert":"true",
        "ecb":"onNotificationAPN"
    });
}

tokenHandlererrorHandler 已定义,onNotificationAPN;

也已定义
function onNotificationAPN(e)
{
    // handle APNS notifications for iOS
    if (e.alert)
    {
        // showing an alert also requires the org.apache.cordova.dialogs plugin
        // Note that I have org.apache.cordova.dialogs aswell
        navigator.notification.alert(e.alert);
        // This code snippet runs fine when the app is open: the app receives the push notification and it's alerted to the user.
    }
    if (e.sound)
    {
        // playing a sound also requires the org.apache.cordova.media plugin
        // Note that I have org.apache.cordova.media plugin aswell
        var snd = new Media(e.sound);
        snd.play();
    }
    if (e.badge)
    {
        pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
        // This code snippet works fine when the app is open: the app receives a push notification and when I close the app the badge count is set to 1, whether that's an expected behavior or not I'm not sure but not what matters right now. 
    }
}

如前所述,当应用程序打开时,该应用程序确实会接收并提醒推送给它的通知。 但是,当应用程序未打开时,设备似乎没有注意到推送。我希望推送通知出现在锁定屏幕和/或状态栏中。

测试设备

我正在 iPad 上进行测试,OS 版本是 7.0.3。

配置文件

我正在使用开发配置文件,我用于测试的设备已添加到苹果开发中心的应用程序设备中。

推送通知的负载

推送通知中发送的负载如下所示:

Msg: {
    "sound":"beeb.wav",
    "alert":"Here is a testing push notification",
    "badge":"1",
    "location":"", // Custom variable
    foreground:"1"
}

我已经尝试将前景变量更改为 0 并将前景替换为背景,但它并没有真正改变任何东西。

通知中心

我已经为应用配置了通知中心,因为它应该是:

帮忙?

我四处看了很多,但我有点空白,如果 Stack-overflow 可以提供帮助,我将不胜感激。平时都是回答问题,现在轮到我提问了:)

推送通知有效负载需要一个 aps 密钥,以及一个包含将显示的消息的警报:

For each notification, compose a JSON dictionary object (as defined by RFC 4627). This dictionary must contain another dictionary identified by the key aps. The aps dictionary can contain one or more properties that specify the following user notification types

  • An alert message to display to the user
  • A number to badge the app icon with
  • A sound to play

More info

有效负载示例:

  {

    "aps" : {

        "alert" : "You got your emails.",

        "badge" : 9,

        "sound" : "bingbong.aiff"

    },

    "acme1" : "bar",

    "acme2" : 42

}

当应用程序在前台时,您会收到整个有效载荷,即使它没有那种格式,您也可以处理它,但是当应用程序在后台或关闭时,系统需要 aps 密钥和警报以及将在通知中心显示的消息。