2016-07-18 01:59:26 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
|
|
|
|
|
|
|
|
2016-03-11 06:25:24 +08:00
|
|
|
/**
|
|
|
|
* @name Local Notifications
|
2016-03-13 07:30:16 +08:00
|
|
|
* @description
|
|
|
|
* This plugin allows you to display local notifications on the device
|
2016-03-11 06:25:24 +08:00
|
|
|
*
|
2016-03-13 07:30:16 +08:00
|
|
|
* @usage
|
2016-07-20 23:17:09 +08:00
|
|
|
* ```typescript
|
|
|
|
* import { LocalNotifications } from 'ionic-native';
|
2016-03-25 01:00:18 +08:00
|
|
|
*
|
|
|
|
*
|
2016-03-11 06:25:24 +08:00
|
|
|
* // Schedule a single notification
|
|
|
|
* LocalNotifications.schedule({
|
|
|
|
* id: 1,
|
2016-07-20 23:17:09 +08:00
|
|
|
* text: 'Single Notification',
|
2016-04-30 11:56:49 +08:00
|
|
|
* sound: isAndroid? 'file://sound.mp3': 'file://beep.caf'
|
2016-03-11 06:25:24 +08:00
|
|
|
* data: { secret: key }
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // Schedule multiple notifications
|
|
|
|
* LocalNotifications.schedule([{
|
|
|
|
* id: 1,
|
2016-07-20 23:17:09 +08:00
|
|
|
* text: 'Multi Notification 1',
|
2016-04-30 11:56:49 +08:00
|
|
|
* sound: isAndroid ? 'file://sound.mp3': 'file://beep.caf',
|
2016-03-11 06:25:24 +08:00
|
|
|
* data: { secret:key }
|
|
|
|
* },{
|
|
|
|
* id: 2,
|
2016-07-20 23:17:09 +08:00
|
|
|
* title: 'Local Notification Example',
|
|
|
|
* text: 'Multi Notification 2',
|
|
|
|
* icon: 'http://example.com/icon.png'
|
2016-03-11 06:25:24 +08:00
|
|
|
* }]);
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // Schedule delayed notification
|
|
|
|
* LocalNotifications.schedule({
|
2016-07-20 23:17:09 +08:00
|
|
|
* text: 'Delayed Notification',
|
2016-04-06 00:41:35 +08:00
|
|
|
* at: new Date(new Date().getTime() + 3600),
|
2016-07-20 23:17:09 +08:00
|
|
|
* led: 'FF0000',
|
2016-03-11 06:25:24 +08:00
|
|
|
* sound: null
|
|
|
|
* });
|
2016-03-14 05:23:24 +08:00
|
|
|
* ```
|
2016-03-11 06:25:24 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-03-13 08:08:47 +08:00
|
|
|
plugin: 'de.appplant.cordova.plugin.local-notification',
|
|
|
|
pluginRef: 'cordova.plugins.notification.local',
|
|
|
|
repo: 'https://github.com/katzer/cordova-plugin-local-notifications'
|
2016-03-11 06:25:24 +08:00
|
|
|
})
|
|
|
|
export class LocalNotifications {
|
|
|
|
|
2016-03-11 06:47:16 +08:00
|
|
|
/**
|
|
|
|
* Schedules a single or multiple notifications
|
|
|
|
* @param options
|
|
|
|
*/
|
2016-03-11 06:25:24 +08:00
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-07-18 01:59:26 +08:00
|
|
|
static schedule(options?: Notification | Array<Notification>): void { }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a previously scheduled notification. Must include the id in the options parameter.
|
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-07-18 01:59:26 +08:00
|
|
|
static update(options?: Notification): void { }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears single or multiple notifications
|
|
|
|
* @param notificationId A single notification id, or an array of notification ids.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static clear(notificationId: any): Promise<any> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears all notifications
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
successIndex: 0,
|
|
|
|
errorIndex: 2
|
|
|
|
})
|
2016-07-18 01:59:26 +08:00
|
|
|
static clearAll(): Promise<any> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels single or multiple notifications
|
|
|
|
* @param notificationId A single notification id, or an array of notification ids.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static cancel(notificationId: any): Promise<any> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all notifications
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
successIndex: 0,
|
|
|
|
errorIndex: 2
|
|
|
|
})
|
2016-07-18 01:59:26 +08:00
|
|
|
static cancelAll(): Promise<any> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks presence of a notification
|
|
|
|
* @param notificationId
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static isPresent(notificationId: number): Promise<boolean> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks is a notification is scheduled
|
|
|
|
* @param notificationId
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static isScheduled(notificationId: number): Promise<boolean> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a notification is triggered
|
|
|
|
* @param notificationId
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static isTriggered(notificationId: number): Promise<boolean> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the notification ids
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getAllIds(): Promise<Array<number>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ids of triggered notifications
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getTriggeredIds(): Promise<Array<number>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ids of scheduled notifications
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getScheduledIds(): Promise<Array<number>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a notification object
|
|
|
|
* @param notificationId The id of the notification to get
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static get(notificationId: any): Promise<Notification> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a scheduled notification object
|
|
|
|
* @param notificationId The id of the notification to get
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getScheduled(notificationId: any): Promise<Notification> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a triggered notification object
|
|
|
|
* @param notificationId The id of the notification to get
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getTriggered(notificationId: any): Promise<Notification> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all notification objects
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getAll(): Promise<Array<Notification>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all scheduled notification objects
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getAllScheduled(): Promise<Array<Notification>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all triggered notification objects
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-07-18 01:59:26 +08:00
|
|
|
static getAllTriggered(): Promise<Array<Notification>> { return; }
|
2016-03-11 06:47:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a callback for a specific event
|
|
|
|
* @param eventName The name of the event. Available events: schedule, trigger, click, update, clear, clearall, cancel, cancelall
|
|
|
|
* @param callback Call back function. All events return notification and state parameter. clear and clearall return state parameter only.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-07-18 01:59:26 +08:00
|
|
|
static on(eventName: string, callback: any): void { }
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-13 07:35:58 +08:00
|
|
|
export interface Notification {
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A unique identifier required to clear, cancel, update or retrieve the local notification in the future
|
|
|
|
* Default: 0
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
id?: number;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* First row of the notification
|
|
|
|
* Default: Empty string (iOS) or the app name (Android)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
title?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Second row of the notification
|
|
|
|
* Default: Empty string
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
text?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The interval at which to reschedule the local notification. That can be a value of second, minute, hour, day, week, month or year
|
|
|
|
* Default: 0 (which means that the system triggers the local notification once)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
every?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* Default: now ~ new Date()
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
at?: any;
|
|
|
|
firstAt?: any;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
* Default: 0 (which means don't show a number)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
badge?: number;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Uri of the file containing the sound to play when an alert is displayed
|
|
|
|
* Default: res://platform_default
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
sound?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Arbitrary data, objects will be encoded to JSON string
|
|
|
|
* Default: null
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
data?: any;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Uri of the icon that is shown in the ticker and notification
|
|
|
|
* Default: res://icon
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
icon?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Uri of the resource (only res://) to use in the notification layouts. Different classes of devices may return different sizes
|
|
|
|
* Default: res://ic_popup_reminder
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
smallIcon?: string;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* Ongoing notifications differ from regular notifications in the following ways:
|
|
|
|
* - They are sorted above the regular notifications in the notification panel
|
|
|
|
* - They do not have an 'X' close button, and are not affected by the "Clear all" button
|
|
|
|
* Default: false
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
ongoing?: boolean;
|
2016-03-11 06:25:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ANDROID ONLY
|
|
|
|
* ARGB value that you would like the LED on the device to blink
|
|
|
|
* Default: FFFFFF
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
led?: string;
|
2016-04-06 00:41:35 +08:00
|
|
|
}
|