Pushgmail notification not showing in status bar or block window for iOS using PushPlugin plugin

Introduction

I am using Phonegap 4.2 (based on Cordova 5.0) to build a cross platform app.

For iOS, I am using Xcode 6.0 and I am using the PushPlugin Cordova plugin to handle Push Notifications.

My problem

I can receive push notifications in the app in the iOS version, but when the app is running in the background, I do not receive any push notifications and they do not appear in the status bar or lock screen. By default I mean when the application is closed.

More details

Referencing

I am including the PushPlugin plugin in the config.xml file correctly:

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

      

I am referencing the JavaScript PushPlugin object correctly in my index.html file:

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

      

Attaching a push notification event

I have correctly bound the notification event to the onNotificationAPN method:

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"
    });
}

      

tokenHandler and errorHandler are defined and are also 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 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 an expected behavior or not I'm not sure but not what matters right now. 
    }
}

      

As stated, the app receives and warns about notifications that have been pressed while the app is open. The device doesn't seem to notice the press, however, when the app isn't open. I expect the push notification to appear on the lock screen and status bar.

Test device

I am testing an iPad, OS version 7.0.3.

Preparation profile

I am using a development provisioning profile and the device I am using for testing has been added to the App Devices in Apple Dev Center.

Push notification payload

The payload sent to Push Push looks like this:

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

      

I tried to change the foreground variable to 0 and replace the foreground with the background, but it doesn't change anything.

Notification Center

I configured the notification center for the app as it should be:

  • Application Icon Icon included.
  • Sounds included.
  • Show in Action Center is enabled.
  • The last 5 elements are included.
  • Show lock screen is on.

reference

I've looked around a lot but I'm kind of empty, I would appreciate if Stack-overflow can help. I usually stick to answering questions, but now it's my turn to ask :)

+3


source to share


1 answer


The push notification payload needs an aps key and an alert with a message to be displayed:

For each notification, create a JSON dictionary object (as defined in RFC 4627). This dictionary should contain another dictionary for key ap. The aps dictionary can contain one or more properties that define the following types of user notifications

  • Warning message to display to user
  • Number to app icon icon with
  • Sound to play

Additional Information



Payload example:

  {

    "aps" : {

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

        "badge" : 9,

        "sound" : "bingbong.aiff"

    },

    "acme1" : "bar",

    "acme2" : 42

}

      

When the app is in the foreground, you get all the payload and you can handle it even if it doesn't have that format, but when the app is in backgroud or closed, the system needs an aps key and an alert with a message to be displayed in notification center.

+2


source







All Articles