UNPKG

2.2 kBMarkdownView Raw
1# Typescript definition file
2
3For those of you who use typescript, we're glad to say that we have the complete definition file available at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).
4Search for `phonegap-plugin-push` there, or simply grab it directly [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/phonegap-plugin-push/phonegap-plugin-push.d.ts).
5
6## Example usage
7
8All objects will be understood as having a defined type, including init options and eventHandler parameters.
9All available attributes and properties will have autocomplete support and type checkings.
10
11```typescript
12let push = PushNotification.init({
13 android: {
14 senderID: "12345679"
15 },
16 ios: {
17 alert: "true",
18 badge: true,
19 sound: 'false'
20 },
21 windows: {}
22});
23
24push.on('registration', (data) => {
25 console.log(data.registrationId);
26});
27
28push.on('notification', (data) => {
29 console.log(data.message);
30 console.log(data.title);
31 console.log(data.count);
32 console.log(data.sound);
33 console.log(data.image);
34 console.log(data.additionalData);
35});
36
37push.on('error', (e) => {
38 console.log(e.message);
39});
40```
41
42If you have custom attributes being sent from the server on the payload, you can define them on a custom interface extending the standard one:
43
44```typescript
45module my.custom {
46 export interface NotificationEventResponse extends PhonegapPluginPush.NotificationEventResponse {
47 additionalData: NotificationEventAdditionalData;
48 }
49
50 export interface NotificationEventAdditionalData extends PhonegapPluginPush.NotificationEventAdditionalData {
51 bacon?: boolean;
52 }
53}
54
55push.on('notification', (data: my.custom.NotificationEventResponse) => {
56 //standard attributes
57 console.log(data.message);
58 console.log(data.title);
59 console.log(data.count);
60 console.log(data.sound);
61 console.log(data.image);
62 console.log(data.additionalData);
63
64 //custom attributes
65 console.log(data.additionalData.bacon);
66});
67```
68
69## Outdated definitions
70
71Is our definition file at DefinitelyTyped outdated? Is there any improvements that could be done?
72We welcome any contribution, and they should be done through issues created [there](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/new).
\No newline at end of file