UNPKG

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