UNPKG

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