1 | // Type definitions for phonegap-plugin-push
|
2 | // Project: https://github.com/phonegap/phonegap-plugin-push
|
3 | // Definitions by: Frederico Galvão <https://github.com/fredgalvao>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 | declare namespace PhonegapPluginPush {
|
7 | type EventResponse = RegistrationEventResponse | NotificationEventResponse | Error
|
8 |
|
9 | interface PushNotification {
|
10 | /**
|
11 | * The event registration will be triggered on each successful registration with the 3rd party push service.
|
12 | * @param event
|
13 | * @param callback
|
14 | */
|
15 | on(event: "registration", callback: (response: RegistrationEventResponse) => any): void
|
16 | /**
|
17 | * The event notification will be triggered each time a push notification is received by a 3rd party push service on the device.
|
18 | * @param event
|
19 | * @param callback
|
20 | */
|
21 | on(event: "notification", callback: (response: NotificationEventResponse) => any): void
|
22 | /**
|
23 | * The event error will trigger when an internal error occurs and the cache is aborted.
|
24 | * @param event
|
25 | * @param callback
|
26 | */
|
27 | on(event: "error", callback: (response: Error) => any): void
|
28 | /**
|
29 | *
|
30 | * @param event Name of the event to listen to. See below(above) for all the event names.
|
31 | * @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
|
46 | */
|
47 | off(event: string, callback: (response: EventResponse) => any): void
|
48 |
|
49 | /**
|
50 | * 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.
|
53 | * @param successHandler
|
54 | * @param errorHandler
|
55 | * @param topics
|
56 | */
|
57 | unregister(successHandler: () => any, errorHandler?: () => any, topics?: string[]): void
|
58 |
|
59 | /**
|
60 | * The subscribe method is used when the application wants to subscribe a new topic to receive push notifications.
|
61 | * @param topic Topic to subscribe to.
|
62 | * @param successHandler Is called when the api successfully unregisters.
|
63 | * @param errorHandler Is called when the api encounters an error while unregistering.
|
64 | */
|
65 | subscribe(topic: string, successHandler: () => any, errorHandler: () => any): void;
|
66 |
|
67 | /**
|
68 | * The unsubscribe method is used when the application no longer wants to receive push notifications
|
69 | * from a specific topic but continue to receive other push messages.
|
70 | * @param topic Topic to unsubscribe from.
|
71 | * @param successHandler Is called when the api successfully unregisters.
|
72 | * @param errorHandler Is called when the api encounters an error while unregistering.
|
73 | */
|
74 | unsubscribe(topic: string, successHandler: () => any, errorHandler: () => any): void;
|
75 |
|
76 | /*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...)*/
|
77 | /**
|
78 | * Set the badge count visible when the app is not running
|
79 | *
|
80 | * The count is an integer indicating what number should show up in the badge.
|
81 | * Passing 0 will clear the badge.
|
82 | * Each notification event contains a data.count value which can be used to set the badge to correct number.
|
83 | * @param successHandler
|
84 | * @param errorHandler
|
85 | * @param count
|
86 | */
|
87 | setApplicationIconBadgeNumber(successHandler: () => any, errorHandler: () => any, count: number): void
|
88 |
|
89 | /**
|
90 | * Get the current badge count visible when the app is not running
|
91 | * successHandler gets called with an integer which is the current badge count
|
92 | * @param successHandler
|
93 | * @param errorHandler
|
94 | */
|
95 | getApplicationIconBadgeNumber(successHandler: (count: number) => any, errorHandler: () => any): void
|
96 |
|
97 | /**
|
98 | * iOS only
|
99 | * Tells the OS that you are done processing a background push notification.
|
100 | * successHandler gets called when background push processing is successfully completed.
|
101 | * @param successHandler
|
102 | * @param errorHandler
|
103 | * @param id
|
104 | */
|
105 | finish(successHandler?: () => any, errorHandler?: () => any, id?: string): void
|
106 |
|
107 | /**
|
108 | * Tells the OS to clear all notifications from the Notification Center
|
109 | * @param successHandler Is called when the api successfully clears the notifications.
|
110 | * @param errorHandler Is called when the api encounters an error when attempting to clears the notifications.
|
111 | */
|
112 | clearAllNotifications(successHandler: () => any, errorHandler: () => any): void
|
113 | }
|
114 |
|
115 | /**
|
116 | * platform specific initialization options.
|
117 | */
|
118 | interface InitOptions {
|
119 | /**
|
120 | * Android specific initialization options.
|
121 | */
|
122 | android?: {
|
123 | /**
|
124 | * Maps to the project number in the Google Developer Console.
|
125 | */
|
126 | senderID: string
|
127 | /**
|
128 | * The name of a drawable resource to use as the small-icon. The name should not include the extension.
|
129 | */
|
130 | icon?: string
|
131 | /**
|
132 | * Sets the background color of the small icon on Android 5.0 and greater.
|
133 | * Supported Formats - http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
|
134 | */
|
135 | iconColor?: string
|
136 | /**
|
137 | * If true it plays the sound specified in the push data or the default system sound. Default is true.
|
138 | */
|
139 | sound?: boolean
|
140 | /**
|
141 | * If true the device vibrates on receipt of notification. Default is true.
|
142 | */
|
143 | vibrate?: boolean
|
144 | /**
|
145 | * If true the app clears all pending notifications when it is closed. Default is true.
|
146 | */
|
147 | clearNotifications?: boolean
|
148 | /**
|
149 | * If true will always show a notification, even when the app is on the foreground. Default is false.
|
150 | */
|
151 | forceShow?: boolean
|
152 | /**
|
153 | * If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic.
|
154 | */
|
155 | topics?: string[]
|
156 | }
|
157 |
|
158 | /**
|
159 | * iOS specific initialization options.
|
160 | */
|
161 | ios?: {
|
162 | /**
|
163 | * If true|"true" the device sets the badge number on receipt of notification.
|
164 | * Default is false|"false".
|
165 | * Note: the value you set this option to the first time you call the init method will be how the application always acts.
|
166 | * Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
|
167 | * This is normal iOS behaviour.
|
168 | */
|
169 | badge?: boolean | string
|
170 | /**
|
171 | * If true|"true" the device plays a sound on receipt of notification.
|
172 | * Default is false|"false".
|
173 | * Note: the value you set this option to the first time you call the init method will be how the application always acts.
|
174 | * Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
|
175 | * This is normal iOS behaviour.
|
176 | */
|
177 | sound?: boolean | string
|
178 | /**
|
179 | * If true|"true" the device shows an alert on receipt of notification.
|
180 | * Default is false|"false".
|
181 | * Note: the value you set this option to the first time you call the init method will be how the application always acts.
|
182 | * Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>App Name.
|
183 | * This is normal iOS behaviour.
|
184 | */
|
185 | alert?: boolean | string
|
186 | /**
|
187 | * If true|"true" the badge will be cleared on app startup. Default is false|"false".
|
188 | */
|
189 | clearBadge?: boolean | string
|
190 | /**
|
191 | * The data required in order to enable Action Buttons for iOS.
|
192 | * Action Buttons on iOS - https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#action-buttons-1
|
193 | */
|
194 | categories?: CategoryArray
|
195 | /**
|
196 | * Maps to the project number in the Google Developer Console. Setting this uses GCM for notifications instead of native
|
197 | */
|
198 | senderID?: string
|
199 | /**
|
200 | * Whether to use prod or sandbox GCM setting. Defaults to false.
|
201 | */
|
202 | fcmSandbox?: boolean
|
203 | /**
|
204 | * If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic. Note: only usable in conjunction with senderID
|
205 | */
|
206 | topics?: string[]
|
207 | }
|
208 |
|
209 | /**
|
210 | * Windows specific initialization options.
|
211 | */
|
212 | windows?: {
|
213 |
|
214 | }
|
215 | }
|
216 |
|
217 | interface CategoryArray {
|
218 | [name: string]: CategoryAction
|
219 | }
|
220 |
|
221 | interface CategoryAction {
|
222 | yes?: CategoryActionData
|
223 | no?: CategoryActionData
|
224 | maybe?: CategoryActionData
|
225 | }
|
226 |
|
227 | interface CategoryActionData {
|
228 | callback: string
|
229 | title: string
|
230 | foreground: boolean
|
231 | destructive: boolean
|
232 | }
|
233 |
|
234 | interface RegistrationEventResponse {
|
235 | /**
|
236 | * The registration ID provided by the 3rd party remote push service.
|
237 | */
|
238 | registrationId: string
|
239 | }
|
240 |
|
241 | interface NotificationEventResponse {
|
242 | /**
|
243 | * The text of the push message sent from the 3rd party service.
|
244 | */
|
245 | message: string
|
246 | /**
|
247 | * The optional title of the push message sent from the 3rd party service.
|
248 | */
|
249 | title?: string
|
250 | /**
|
251 | * The number of messages to be displayed in the badge iOS or message count in the notification shade in Android.
|
252 | * For windows, it represents the value in the badge notification which could be a number or a status glyph.
|
253 | */
|
254 | count: string
|
255 | /**
|
256 | * The name of the sound file to be played upon receipt of the notification.
|
257 | */
|
258 | sound: string
|
259 | /**
|
260 | * The path of the image file to be displayed in the notification.
|
261 | */
|
262 | image: string
|
263 | /**
|
264 | * An optional collection of data sent by the 3rd party push service that does not fit in the above properties.
|
265 | */
|
266 | additionalData: NotificationEventAdditionalData
|
267 | }
|
268 |
|
269 | /**
|
270 | * TODO: document all possible properties (I only got the android ones)
|
271 | *
|
272 | * Loosened up with a dictionary notation, but all non-defined properties need to use (map['prop']) notation
|
273 | *
|
274 | * Ideally the developer would overload (merged declaration) this or create a new interface that would extend this one
|
275 | * so that he could specify any custom code without having to use array notation (map['prop']) for all of them.
|
276 | */
|
277 | interface NotificationEventAdditionalData {
|
278 | [name: string]: any
|
279 |
|
280 | /**
|
281 | * Whether the notification was received while the app was in the foreground
|
282 | */
|
283 | foreground?: boolean
|
284 | /**
|
285 | * Will be true if the application is started by clicking on the push notification, false if the app is already started. (Android/iOS only)
|
286 | */
|
287 | coldstart?: boolean
|
288 | collapse_key?: string
|
289 | from?: string
|
290 | notId?: string
|
291 | }
|
292 |
|
293 | interface PushNotificationStatic {
|
294 | init(options: InitOptions): PushNotification
|
295 | new (options: InitOptions): PushNotification
|
296 | }
|
297 | }
|
298 |
|
299 | interface Window {
|
300 | PushNotification: PhonegapPluginPush.PushNotificationStatic
|
301 | }
|
302 | declare var PushNotification: PhonegapPluginPush.PushNotificationStatic;
|