· 7 years ago · Apr 06, 2018, 05:30 AM
1import {IonicNativePlugin} from '@ionic-native/core';
2
3export interface ILocalNotification {
4 /**
5 * A unique identifier required to clear, cancel, update or retrieve the local notification in the future
6 * Default: 0
7 */
8 id?: number;
9 /**
10 * First row of the notification
11 * Default: Empty string (iOS) or the app name (Android)
12 */
13 title?: string;
14 /**
15 * Second row of the notification
16 * Default: Empty string
17 */
18 text?: string;
19 /**
20 * The interval at which to reschedule the local notification. That can be a value of second, minute, hour, day, week, month or year
21 * Default: 0 (which means that the system triggers the local notification once)
22 */
23 every?: string;
24 /**
25 * The interval time is extended by this. It's with number of you are using this and you reschedule the local notification as per your requirement.
26 * Default: 1 (which means that the system triggers interval time of your local notification is one)
27 */
28 interval?: number;
29 /**
30 * The date and time when the system should deliver the local notification. If the specified value is nil or is a date in the past, the local notification is delivered immediately.
31 * Default: now ~ new Date()
32 */
33 at?: any;
34 firstAt?: any;
35 /**
36 * The number currently set as the badge of the app icon in Springboard (iOS) or at the right-hand side of the local notification (Android)
37 * Default: 0 (which means don't show a number)
38 */
39 badge?: number;
40 /**
41 * Uri of the file containing the sound to play when an alert is displayed
42 * Default: res://platform_default
43 */
44 sound?: string;
45 /**
46 * Arbitrary data, objects will be encoded to JSON string
47 * Default: null
48 */
49 data?: any;
50 /**
51 * ANDROID ONLY
52 * Uri of the icon that is shown in the ticker and notification
53 * Default: res://icon
54 */
55 icon?: string;
56 /**
57 * ANDROID ONLY
58 * Uri of the resource (only res://) to use in the notification layouts. Different classes of devices may return different sizes
59 * Default: res://ic_popup_reminder
60 */
61 smallIcon?: string;
62 /**
63 * ANDROID ONLY
64 * RGB value for the background color of the smallIcon.
65 * Default: Androids COLOR_DEFAULT, which will vary based on Android version.
66 */
67 color?: string;
68 /**
69 * ANDROID ONLY
70 * Ongoing notifications differ from regular notifications in the following ways:
71 * - They are sorted above the regular notifications in the notification panel
72 * - They do not have an 'X' close button, and are not affected by the "Clear all" button
73 * Default: false
74 */
75 ongoing?: boolean;
76 /**
77 * ANDROID ONLY
78 * ARGB value that you would like the LED on the device to blink
79 * Default: FFFFFF
80 */
81 led?: string;
82 /**
83 * Notification priority.
84 */
85 priority?: number;
86 /**
87 * Is a silent notification
88 */
89 silent?: boolean;
90}
91
92/**
93 * @name Local Notifications
94 * @description
95 * This plugin allows you to display local notifications on the device
96 *
97 * @usage
98 * ```typescript
99 * import { LocalNotifications } from '@ionic-native/local-notifications';
100 *
101 *
102 * constructor(private localNotifications: LocalNotifications) { }
103 *
104 * ...
105 *
106 *
107 * // Schedule a single notification
108 * this.localNotifications.schedule({
109 * id: 1,
110 * text: 'Single ILocalNotification',
111 * sound: isAndroid? 'file://sound.mp3': 'file://beep.caf',
112 * data: { secret: key }
113 * });
114 *
115 *
116 * // Schedule multiple notifications
117 * this.localNotifications.schedule([{
118 * id: 1,
119 * text: 'Multi ILocalNotification 1',
120 * sound: isAndroid ? 'file://sound.mp3': 'file://beep.caf',
121 * data: { secret:key }
122 * },{
123 * id: 2,
124 * title: 'Local ILocalNotification Example',
125 * text: 'Multi ILocalNotification 2',
126 * icon: 'http://example.com/icon.png'
127 * }]);
128 *
129 *
130 * // Schedule delayed notification
131 * this.localNotifications.schedule({
132 * text: 'Delayed ILocalNotification',
133 * at: new Date(new Date().getTime() + 3600),
134 * led: 'FF0000',
135 * sound: null
136 * });
137 * ```
138 * @interfaces
139 * ILocalNotification
140 */
141export declare class LocalNotifications extends IonicNativePlugin {
142 /**
143 * Schedules a single or multiple notifications
144 * @param options {Notification | Array<ILocalNotification>} optional
145 */
146 schedule(options?: ILocalNotification | Array<ILocalNotification>): void;
147
148 /**
149 * Updates a previously scheduled notification. Must include the id in the options parameter.
150 * @param options {ILocalNotification} optional
151 */
152 update(options?: ILocalNotification): void;
153
154 /**
155 * Clears single or multiple notifications
156 * @param notificationId {any} A single notification id, or an array of notification ids.
157 * @returns {Promise<any>} Returns a promise when the notification had been cleared
158 */
159 clear(notificationId: any): Promise<any>;
160
161 /**
162 * Clears all notifications
163 * @returns {Promise<any>} Returns a promise when all notifications have cleared
164 */
165 clearAll(): Promise<any>;
166
167 /**
168 * Cancels single or multiple notifications
169 * @param notificationId {any} A single notification id, or an array of notification ids.
170 * @returns {Promise<any>} Returns a promise when the notification is canceled
171 */
172 cancel(notificationId: any): Promise<any>;
173
174 /**
175 * Cancels all notifications
176 * @returns {Promise<any>} Returns a promise when all notifications are canceled
177 */
178 cancelAll(): Promise<any>;
179
180 /**
181 * Checks presence of a notification
182 * @param notificationId {number}
183 * @returns {Promise<boolean>}
184 */
185 isPresent(notificationId: number): Promise<boolean>;
186
187 /**
188 * Checks is a notification is scheduled
189 * @param notificationId {number}
190 * @returns {Promise<boolean>}
191 */
192 isScheduled(notificationId: number): Promise<boolean>;
193
194 /**
195 * Checks if a notification is triggered
196 * @param notificationId {number}
197 * @returns {Promise<boolean>}
198 */
199 isTriggered(notificationId: number): Promise<boolean>;
200
201 /**
202 * Get all the notification ids
203 * @returns {Promise<Array<number>>}
204 */
205 getAllIds(): Promise<Array<number>>;
206
207 /**
208 * Get the ids of triggered notifications
209 * @returns {Promise<Array<number>>}
210 */
211 getTriggeredIds(): Promise<Array<number>>;
212
213 /**
214 * Get the ids of scheduled notifications
215 * @returns {Promise<Array<number>>} Returns a promise
216 */
217 getScheduledIds(): Promise<Array<number>>;
218
219 /**
220 * Get a notification object
221 * @param notificationId {any} The id of the notification to get
222 * @returns {Promise<ILocalNotification>}
223 */
224 get(notificationId: any): Promise<ILocalNotification>;
225
226 /**
227 * Get a scheduled notification object
228 * @param notificationId {any} The id of the notification to get
229 * @returns {Promise<ILocalNotification>}
230 */
231 getScheduled(notificationId: any): Promise<ILocalNotification>;
232
233 /**
234 * Get a triggered notification object
235 * @param notificationId The id of the notification to get
236 * @returns {Promise<ILocalNotification>}
237 */
238 getTriggered(notificationId: any): Promise<ILocalNotification>;
239
240 /**
241 * Get all notification objects
242 * @returns {Promise<Array<ILocalNotification>>}
243 */
244 getAll(): Promise<Array<ILocalNotification>>;
245
246 /**
247 * Get all scheduled notification objects
248 * @returns {Promise<Array<ILocalNotification>>}
249 */
250 getAllScheduled(): Promise<Array<ILocalNotification>>;
251
252 /**
253 * Get all triggered notification objects
254 * @returns {Promise<Array<ILocalNotification>>}
255 */
256 getAllTriggered(): Promise<Array<ILocalNotification>>;
257
258 /**
259 * Request permission to show notifications if not already granted.
260 * @returns {Promise<boolean>}
261 */
262 requestPermission(): Promise<boolean>;
263
264 /**
265 * Informs if the app has the permission to show notifications.
266 * @returns {Promise<boolean>}
267 */
268 hasPermission(): Promise<boolean>;
269
270 /**
271 * Sets a callback for a specific event
272 * @param eventName The name of the event. Available events: schedule, trigger, click, update, clear, clearall, cancel, cancelall
273 * @param callback Call back function. All events return notification and state parameter. clear and clearall return state parameter only.
274 */
275 on(eventName: string, callback: any): void;
276
277 /**
278 * Removes a callback of a specific event
279 * @param eventName The name of the event. Available events: schedule, trigger, click, update, clear, clearall, cancel, cancelall
280 * @param callback Call back function. All events return notification and state parameter. clear and clearall return state parameter only.
281 */
282 un(eventName: string, callback: any): void;
283}