Chia-Yu Pai
Chia-Yu Pai

Reputation: 721

Phonegap (Cordova) iOS Push Notification onNotificationAPN event triggered in the background

I use Phonegap 3.0 with PushPlugin plugin to implement iOS Push Notification Service

With node-apn package backend server, I can receive APN message from it. And registered onNotificationAPN function will be triggered in the background and APP icon had a badge count too.

But I cannot store the event.payload to localStorage even window Object.

So.. If I wanna get the APN payload data when user revoke app from background (or just click notification). How can I do?

PS. I registered resume event when App initial before backgrounded, and confirmed called when the App revoke.

Sample Code:

function onNotificationAPN (event) {
    if ( event.alert )
    {
        navigator.notification.alert(event.alert);
    }

    if ( event.sound )
    {
        var snd = new Media(event.sound);
        snd.play();
    }

    if ( event.badge )
    {
        pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
    }

    if ( event.payload )
    {
        localStorage.payload = event.payload   
    }

    // Assign here useless too.
}

document.addEventListener("resume", pushRevoke, false);

function pushRevoke(){
    var payload = localStorage.payload; // undefined
}

Upvotes: 2

Views: 4115

Answers (1)

Chia-Yu Pai
Chia-Yu Pai

Reputation: 721

Resolved

Because of PushPlugin JSON Parser Error

In ios / PushPlugin.m Line 171

[jsonStr appendFormat:@"foreground:'%d',", 0];

Should be

[jsonStr appendFormat:@"foreground:'%d'", 0];

Github Issue

Upvotes: 4

Related Questions