Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(): Phonegap local notifications #1474

Merged
merged 16 commits into from
May 9, 2017
106 changes: 106 additions & 0 deletions src/@ionic-native/plugins/phonegap-plugin-local-notification/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Injectable } from '@angular/core';
import { Cordova, CordovaInstance, Plugin, IonicNativePlugin, checkAvailability } from '@ionic-native/core';

declare var Notification: any;
// can use a shorter name here, like PLNObject ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

export class PLNObject {

private _objectInstance: any;

constructor(title: string, options: any) {
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-notifications
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name needs to be Phonegap Local Notification ... also directory name should be phonegap-local-notification

* @description
* This plugin does something
*
* @usage
* ```
* import { PhonegapLocalNotifications } from '@ionic-native/phonegap-local-notifications';
*
*
* constructor(private localNotification: PhonegapLocalNotifications) { }
*
* ...
*
* this.localNotification.requestPermission().then(
* (permission) => {
* if (permission === ‘granted’) {
* let notification = new Notification(“My title”, {
* tag: ‘message1’,
* body: “My body”
* });
* }
* }
* );
*
* ```
*/
@Plugin({
pluginName: 'Phonegap Loca Notifications',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a typo here.. Loca -> Local

plugin: 'phonegap-local-notifications',
pluginRef: 'Notification',
repo: 'https://github.com/phonegap/phonegap-plugin-local-notification',
platforms: ['Android', 'iOS']
})
@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.
*/
@Cordova()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove this decorator because it will override the functionality you wrote

create(title: string, options: any) { return new PLNObject(title, options); }
/**
* requests permission from the user to show a local notification.
* @param {Promise<any>}
*/
@Cordova()
requestPermission(): Promise<any> { return; }

/**
* closes an open notification.
*/
close(): void { }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the close() method from here. It's an instance method, you already got it in PLNObject.

See https://github.com/phonegap/phonegap-plugin-local-notification/blob/master/www/notification.js#L80


}