Ionic 2 with ng-cordova

NishanthKabra, thank you very much.

Do you also know how to be able to extend the plugin?
I need to have some extra properties on data.additionalData.

Tried to extend the interface as it was documented here
, yet that failed miserably; Netbeans already indicates ‘cannot find namespace PhonegapPluginPush’.

Do you know what namespace I should use, or maybe a totally different approach?

module my.custom {
    export interface NotificationEventResponse extends PhonegapPluginPush.NotificationEventResponse {
        additionalData: NotificationEventAdditionalData;
    }

    export interface NotificationEventAdditionalData extends PhonegapPluginPush.NotificationEventAdditionalData {
        bacon?: boolean;
    }
}

push.on('notification', (data: my.custom.NotificationEventResponse) => {
    //standard attributes
    console.log(data.message);
    console.log(data.title);
    console.log(data.count);
    console.log(data.sound);
    console.log(data.image);
    console.log(data.additionalData);

    //custom attributes
    console.log(data.additionalData.bacon);
});

//// the rest is irrelevant because it won’t even compile

Add this following code in your ts and should be working.
As of now i am consuming additional data from server.
Client Side changes: Change1
Before your @App annotation add this in you app.ts.

export interface NotificationEventResponse extends PhonegapPluginPush.NotificationEventResponse {
additionalData: NotificationEventAdditionalData;
}

export interface NotificationEventAdditionalData extends PhonegapPluginPush.NotificationEventAdditionalData {
additionalData?: any;
}

Client Side changes: Change2 Updating notification data to have additional data:

push.on(‘notification’, (data:NotificationEventResponse) => {
console.log(data.additionalData.additionalData);
});

Server side changes: Change 1
message.addData(‘title’, ‘Title’);
message.addData(‘message’, “Message”);
message.addData(‘sound’, ‘default’);
var data = {};
data.type = “lunch”;
message.addData(‘additionalData’, data);

You should be able to receive additional data.type as lunch in your client.

In an Ionic V2 app?

I tried just like you said (before already), and get:
TypeScript error: app/app.ts(14,52): Error TS2503: Cannot find namespace ‘PhonegapPluginPush’.

[edit] I’m sorry, I’ve used Push from ionic-native. But cannot find the correct namespace for it, because I don’t know how to, haha… Now I’ve hacked it by using push.on(‘notification’, (data: any) => {/ ,

With an any type: TypeScript usefulness > /dev/null

1 Like

I have a similar problem, i can’t import the plugin’s functions to my project and use it.
I’m trying to find a solution, but I’m going crazy.

Here there is a Ionic1 project, but i need a working one for Ionic2. :disappointed_relieved:
http://devgirl.org/2016/01/08/speaking-with-cordova/