Skip to content

Commit fb2b3b1

Browse files
committed
Merge pull request DefinitelyTyped#6917 from fredgalvao/phonegap-plugin-push-1.4.4
Phonegap plugin push 1.4.4
2 parents 98b4177 + 1775824 commit fb2b3b1

File tree

2 files changed

+143
-54
lines changed

2 files changed

+143
-54
lines changed
Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
/// <reference path="phonegap-plugin-push.d.ts" />
22

33
function test() {
4-
var options:PhonegapPluginPush.InitOptions = {
4+
let options: PhonegapPluginPush.InitOptions = {
55
android: {
66
senderID: '123456789',
77
icon: 'phonegap',
88
iconColor: 'blue',
99
sound: true,
1010
vibrate: true,
11-
clearNotifications: false
11+
clearNotifications: false,
12+
forceShow: true
1213
},
1314
ios: {
1415
badge: true,
1516
sound: true,
16-
alert: true
17+
alert: true,
18+
clearBadge: true
1719
},
1820
windows: {}
1921
};
20-
var push:PhonegapPluginPush.PushNotification;
22+
23+
let iosStringOptions = {
24+
badge: 'true',
25+
sound: 'true',
26+
alert: 'true',
27+
clearBadge: 'true'
28+
};
29+
30+
options.ios = iosStringOptions;
31+
32+
let push: PhonegapPluginPush.PushNotification;
2133

2234
/*from constructor*/
2335
push = new PushNotification(options);
36+
push = new window.PushNotification(options);
2437

2538
push.unregister(() => {
2639
console.log('did unregister');
@@ -30,12 +43,13 @@ function test() {
3043

3144
/*from init*/
3245
push = PushNotification.init(options);
46+
push = window.PushNotification.init(options);
3347

34-
push.on('registration', (data:PhonegapPluginPush.RegistrationEventResponse) => {
48+
let registrationHandler = (data: PhonegapPluginPush.RegistrationEventResponse) => {
3549
console.log(data.registrationId);
36-
});
50+
};
3751

38-
push.on('notification', (data:PhonegapPluginPush.NotificationEventResponse) => {
52+
let notificationHandler = (data: PhonegapPluginPush.NotificationEventResponse) => {
3953
console.log(data.message);
4054
console.log(data.title);
4155
console.log(data.count);
@@ -45,15 +59,35 @@ function test() {
4559
/*the rest of the additional fields are not 'canon'*/
4660
console.log(data.additionalData);
4761
console.log(data.additionalData.foreground);
48-
});
4962

50-
push.on('error', (e:Error) => {
63+
push.finish(() => {
64+
console.log('did finish');
65+
}, () => {
66+
console.log('did not finish');
67+
});
68+
};
69+
70+
let errorHandler = (e: Error) => {
5171
console.log(e.message);
52-
});
72+
};
73+
74+
push.on('registration', registrationHandler);
75+
push.on('notification', notificationHandler);
76+
push.on('error', errorHandler);
77+
78+
push.off('registration', registrationHandler);
79+
push.off('notification', notificationHandler);
80+
push.off('error', errorHandler);
5381

5482
push.setApplicationIconBadgeNumber(() => {
5583
console.log('did setApplicationIconBadgeNumber');
5684
}, () => {
5785
console.log('did not setApplicationIconBadgeNumber');
5886
}, 1);
87+
88+
push.getApplicationIconBadgeNumber((count: number) => {
89+
console.log('did getApplicationIconBadgeNumber', count);
90+
}, () => {
91+
console.log('did not getApplicationIconBadgeNumber');
92+
});
5993
}

phonegap-plugin-push/phonegap-plugin-push.d.ts

Lines changed: 99 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,77 @@ declare module PhonegapPluginPush {
1212
* @param event
1313
* @param callback
1414
*/
15-
on(event:"registration", callback:(response:RegistrationEventResponse)=>any):void
15+
on(event: "registration", callback: (response: RegistrationEventResponse) => any): void
1616
/**
1717
* The event notification will be triggered each time a push notification is received by a 3rd party push service on the device.
1818
* @param event
1919
* @param callback
2020
*/
21-
on(event:"notification", callback:(response:NotificationEventResponse)=>any):void
21+
on(event: "notification", callback: (response: NotificationEventResponse) => any): void
2222
/**
2323
* The event error will trigger when an internal error occurs and the cache is aborted.
2424
* @param event
2525
* @param callback
2626
*/
27-
on(event:"error", callback:(response:Error)=>any):void
28-
/*Generic one, needed for the overloads*/
27+
on(event: "error", callback: (response: Error) => any): void
2928
/**
3029
*
3130
* @param event Name of the event to listen to. See below(above) for all the event names.
3231
* @param callback is called when the event is triggered.
32+
* @param event
33+
* @param callback
34+
*/
35+
on(event: string, callback: (response: EventResponse) => any): void
36+
37+
off(event: "registration", callback: (response: RegistrationEventResponse) => any): void
38+
off(event: "notification", callback: (response: NotificationEventResponse) => any): void
39+
off(event: "error", callback: (response: Error) => any): void
40+
/**
41+
* As stated in the example, you will have to store your event handler if you are planning to remove it.
42+
* @param event Name of the event type. The possible event names are the same as for the push.on function.
43+
* @param callback handle to the function to get removed.
44+
* @param event
45+
* @param callback
3346
*/
34-
on(event:string, callback:(response:EventResponse)=>any):void
47+
off(event: string, callback: (response: EventResponse) => any): void
3548

3649
/**
3750
* The unregister method is used when the application no longer wants to receive push notifications.
51+
* Beware that this cleans up all event handlers previously registered,
52+
* so you will need to re-register them if you want them to function again without an application reload.
3853
* @param successHandler
3954
* @param errorHandler
4055
*/
41-
unregister(successHandler:()=>any, errorHandler?:()=>any):void
56+
unregister(successHandler: () => any, errorHandler?: () => any): void
57+
4258
/*TODO according to js source code, "errorHandler" is optional, but is "count" also optional? I can't read objetive-C code (can anyone at all? I wonder...)*/
4359
/**
4460
* Set the badge count visible when the app is not running
4561
*
46-
* The count is an integer indicating what number should show up in the badge. Passing 0 will clear the badge. Each notification event contains a data.count value which can be used to set the badge to correct number.
62+
* The count is an integer indicating what number should show up in the badge.
63+
* Passing 0 will clear the badge.
64+
* Each notification event contains a data.count value which can be used to set the badge to correct number.
4765
* @param successHandler
4866
* @param errorHandler
4967
* @param count
5068
*/
51-
setApplicationIconBadgeNumber(successHandler:()=>any, errorHandler:()=>any, count:number):void
69+
setApplicationIconBadgeNumber(successHandler: () => any, errorHandler: () => any, count: number): void
70+
/**
71+
* Get the current badge count visible when the app is not running
72+
* successHandler gets called with an integer which is the current badge count
73+
* @param successHandler
74+
* @param errorHandler
75+
*/
76+
getApplicationIconBadgeNumber(successHandler: (count: number) => any, errorHandler: () => any): void
77+
78+
/**
79+
* iOS only
80+
* Tells the OS that you are done processing a background push notification.
81+
* successHandler gets called when background push processing is successfully completed.
82+
* @param successHandler
83+
* @param errorHandler
84+
*/
85+
finish(successHandler: () => any, errorHandler: () => any): void
5286
}
5387

5488
/**
@@ -62,46 +96,66 @@ declare module PhonegapPluginPush {
6296
/**
6397
* Maps to the project number in the Google Developer Console.
6498
*/
65-
senderID:string
99+
senderID: string
66100
/**
67-
* The name of a drawable resource to use as the small-icon.
101+
* The name of a drawable resource to use as the small-icon. The name should not include the extension.
68102
*/
69-
icon?:string
103+
icon?: string
70104
/**
71-
* Sets the background color of the small icon.
105+
* Sets the background color of the small icon on Android 5.0 and greater.
72106
* Supported Formats - http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
73107
*/
74-
iconColor?:string
108+
iconColor?: string
75109
/**
76110
* If true it plays the sound specified in the push data or the default system sound. Default is true.
77111
*/
78-
sound?:boolean
112+
sound?: boolean
79113
/**
80114
* If true the device vibrates on receipt of notification. Default is true.
81115
*/
82-
vibrate?:boolean
116+
vibrate?: boolean
83117
/**
84118
* If true the app clears all pending notifications when it is closed. Default is true.
85119
*/
86-
clearNotifications?:boolean
120+
clearNotifications?: boolean
121+
/**
122+
* If true will always show a notification, even when the app is on the foreground. Default is false.
123+
*/
124+
forceShow?: boolean
87125
}
88126

89127
/**
90128
* iOS specific initialization options.
91129
*/
92130
ios?: {
93131
/**
94-
* If true the device shows an alert on receipt of notification. Default is false.
132+
* If true|"true" the device sets the badge number on receipt of notification.
133+
* Default is false|"false".
134+
* Note: the value you set this option to the first time you call the init method will be how the application always acts.
135+
* Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
136+
* This is normal iOS behaviour.
95137
*/
96-
badge?: boolean
138+
badge?: boolean | string
97139
/**
98-
* If true the device sets the badge number on receipt of notification. Default is false.
140+
* If true|"true" the device plays a sound on receipt of notification.
141+
* Default is false|"false".
142+
* Note: the value you set this option to the first time you call the init method will be how the application always acts.
143+
* Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
144+
* This is normal iOS behaviour.
99145
*/
100-
sound?: boolean
146+
sound?: boolean | string
147+
/**
148+
* If true|"true" the device shows an alert on receipt of notification.
149+
* Default is false|"false".
150+
* Note: the value you set this option to the first time you call the init method will be how the application always acts.
151+
* Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
152+
* This is normal iOS behaviour.
153+
*/
154+
alert?: boolean | string
101155
/**
102-
* If true the device plays a sound on receipt of notification. Default is false.
156+
* If true|"true" the badge will be cleared on app startup. Default is false|"false".
103157
*/
104-
alert?: boolean
158+
clearBadge?: boolean | string
105159
}
106160

107161
/**
@@ -116,63 +170,64 @@ declare module PhonegapPluginPush {
116170
/**
117171
* The registration ID provided by the 3rd party remote push service.
118172
*/
119-
registrationId:string
173+
registrationId: string
120174
}
121175

122176
interface NotificationEventResponse {
123177
/**
124178
* The text of the push message sent from the 3rd party service.
125179
*/
126-
message:string
180+
message: string
127181
/**
128182
* The optional title of the push message sent from the 3rd party service.
129183
*/
130-
title?:string
184+
title?: string
131185
/**
132186
* The number of messages to be displayed in the badge iOS or message count in the notification shade in Android.
133187
* For windows, it represents the value in the badge notification which could be a number or a status glyph.
134188
*/
135-
count:string
189+
count: string
136190
/**
137191
* The name of the sound file to be played upon receipt of the notification.
138192
*/
139-
sound:string
193+
sound: string
140194
/**
141195
* The path of the image file to be displayed in the notification.
142196
*/
143-
image:string
197+
image: string
144198
/**
145199
* An optional collection of data sent by the 3rd party push service that does not fit in the above properties.
146200
*/
147201
additionalData: NotificationEventAdditionalData
148202
}
149203

204+
/**
205+
* TODO: document all possible properties (I only got the android ones)
206+
*
207+
* Loosened up with a dictionary notation, but all non-defined properties need to use (map['prop']) notation
208+
*
209+
* Ideally the developer would overload (merged declaration) this or create a new interface that would extend this one
210+
* so that he could specify any custom code without having to use array notation (map['prop']) for all of them.
211+
*/
150212
interface NotificationEventAdditionalData {
151-
/**
152-
* TODO: document all possible properties (I only got the android ones)
153-
*
154-
* Loosened up with a dictionary notation, but all non-defined properties need to use (map['prop']) notation
155-
*
156-
* Ideally the developer would overload (merged declaration) this or create a new interface that would extend this one
157-
* so that he could specify any custom code without having to use array notation (map['prop']) for all of them.
158-
*/
159213
[name: string]: any
214+
160215
/**
161216
* Whether the notification was received while the app was in the foreground
162217
*/
163-
foreground?:boolean
164-
collapse_key?:string
165-
from?:string
166-
notId?:string
218+
foreground?: boolean
219+
collapse_key?: string
220+
from?: string
221+
notId?: string
167222
}
168223

169224
interface PushNotificationStatic {
170-
init(options:InitOptions):PushNotification
171-
new(options:InitOptions):PushNotification
225+
init(options: InitOptions): PushNotification
226+
new (options: InitOptions): PushNotification
172227
}
173228
}
174229

175230
interface Window {
176-
PushNotification:PhonegapPluginPush.PushNotificationStatic
231+
PushNotification: PhonegapPluginPush.PushNotificationStatic
177232
}
178-
declare var PushNotification:PhonegapPluginPush.PushNotificationStatic;
233+
declare var PushNotification: PhonegapPluginPush.PushNotificationStatic;

0 commit comments

Comments
 (0)