Phonegap Local Notification
The Local Notification plugin gives developers the ability to post notifications from their app that show up in the device’s notification area. The API for the local notification plugin follows the W3C Web Notifications specification: https://www.w3.org/TR/notifications/
Repo: https://github.com/phonegap/phonegap-plugin-local-notification
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add phonegap-plugin-local-notification $ npm install --save @ionic-native/phonegap-local-notification@4
- Add this plugin to your app's module
Supported platforms
- Android
- Browser
- iOS
- Windows
Usage
import { PhonegapLocalNotification } from '@ionic-native/phonegap-local-notification';
constructor(private localNotification: PhonegapLocalNotification) { }
...
this.localNotification.requestPermission().then(
(permission) => {
if (permission === 'granted') {
// Create the notification
this.localNotification.create('My Title', {
tag: 'message1',
body: 'My body',
icon: 'assets/icon/favicon.ico'
});
}
}
);
Instance Members
create(title, Options)
A global object that lets you interact with the Notification API.
Param | Type | Details |
---|---|---|
title |
string
|
Title of the local notification. |
Options |
LocalNotificationOptions
|
An object containing optional property/value pairs. |
Returns: PLNObject
requestPermission()
requests permission from the user to show a local notification.
Returns: Promise<any>
LocalNotificationOptions
Param | Type | Details |
---|---|---|
dir |
string
|
Sets the direction of the notification. One of "auto", "ltr" or "rtl" (optional) |
lang |
string
|
Sets the language of the notification (optional) |
body |
string
|
Sets the body of the notification (optional) |
tag |
string
|
Sets the identifying tag of the notification (optional) |
icon |
string
|
Sets the icon of the notification (optional) |