feat(phonegap-local-notifications): add Phonegap local notifications plugin (#1474)
* typo(barcode-scanner): fixe circle lint error * typo(docs): Unified the documentations In some plugins the typescript markup was missing. I also unified the console.log string from console.log("hello") to console.log('Hello') so any plugin page look the same. * added phonegap-local-notifications * update #1 * update #3 * update #4 * cleaned up the usage part * removed old folder * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts
This commit is contained in:
parent
6855fe8f7d
commit
3d747d38b2
110
src/@ionic-native/plugins/phonegap-local-notification/index.ts
Normal file
110
src/@ionic-native/plugins/phonegap-local-notification/index.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Cordova, CordovaInstance, Plugin, IonicNativePlugin, checkAvailability } from '@ionic-native/core';
|
||||||
|
|
||||||
|
declare var Notification: any;
|
||||||
|
|
||||||
|
export class PLNObject {
|
||||||
|
|
||||||
|
private _objectInstance: any;
|
||||||
|
|
||||||
|
constructor(title: string, options: LocalNotificationOptions) {
|
||||||
|
if (checkAvailability('Notification') === true) {
|
||||||
|
this._objectInstance = new Notification(title, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@CordovaInstance({ sync: true })
|
||||||
|
close(): void { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LocalNotificationOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction of the notification. One of "auto", "ltr" or "rtl"
|
||||||
|
*/
|
||||||
|
dir?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the language of the notification
|
||||||
|
*/
|
||||||
|
lang?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the body of the notification
|
||||||
|
*/
|
||||||
|
body?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the identifying tag of the notification
|
||||||
|
*/
|
||||||
|
tag?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the icon of the notification
|
||||||
|
*/
|
||||||
|
icon?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Phonegap Local Notification
|
||||||
|
* @description
|
||||||
|
* 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/
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
* ```
|
||||||
|
* import { PhonegapLocalNotifications } from '@ionic-native/phonegap-local-notifications';
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* constructor(private localNotification: PhonegapLocalNotifications) { }
|
||||||
|
*
|
||||||
|
* ...
|
||||||
|
*
|
||||||
|
* 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'
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @interfaces
|
||||||
|
* LocalNotificationOptions
|
||||||
|
*/
|
||||||
|
@Plugin({
|
||||||
|
pluginName: 'Phonegap Local Notifications',
|
||||||
|
plugin: 'phonegap-local-notifications',
|
||||||
|
pluginRef: 'Notification',
|
||||||
|
repo: 'https://github.com/phonegap/phonegap-plugin-local-notification',
|
||||||
|
platforms: ['Android', 'iOS', 'Browser']
|
||||||
|
})
|
||||||
|
@Injectable()
|
||||||
|
export class PhonegapLocalNotifications extends IonicNativePlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A global object that lets you interact with the Notification API.
|
||||||
|
* @param title {string} Title of the local notification.
|
||||||
|
* @param Options {LocalNotificationOptions} An object containing optional property/value pairs.
|
||||||
|
* @returns {PLNObject}
|
||||||
|
*/
|
||||||
|
create(title: string, options: LocalNotificationOptions) { return new PLNObject(title, options); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requests permission from the user to show a local notification.
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
requestPermission(): Promise<any> { return; }
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user