This commit is contained in:
nicco
2018-09-04 19:47:42 +02:00
parent 8ba2030bb3
commit 94c02d6a2e
472 changed files with 63790 additions and 12 deletions

View File

@@ -0,0 +1,26 @@
# Change Log
## [v1.0.0](https://github.com/phonegap/phonegap-plugin-local-notification/tree/v1.0.0) (2017-04-24)
[Full Changelog](https://github.com/phonegap/phonegap-plugin-local-notification/compare/v0.0.1...v1.0.0)
- 1.0.0 [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/8885886b2a689b26231b7706db98fa0d3bc58ef1)
- :bookmark: Bumping plugin version to 1.0.0 [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/fe3a598f8512ee9078208a14f133c83430b76663)
- :wrench: adding LICENSE file [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/f7646f9c214fc419b5be18ffdc11802768d44102)
- :beer::memo: Issue #2: Instrument notification.js with jsdocs [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/afd2111b2f66490ed2fb1ddba34c66e80c880e1f)
- :heavy_plus_sign: add js2docs package [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/5dc3ab5b07b89dcba9343b5ef000baac19526f38)
- :hammer: cleaning up iOS code [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/0ee8cc57759ff7f725d89617ea869fb52ef96296)
- :apple: Implement click event firing for iOS [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/c6ee0376cfd735b65f8da831f998302684f2d418)
- :penguin: Implement click event firing [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/75747b93590f6deb66e4cac7acb52b56ea093fff)
- :penguin: Implement show and close events for Android [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/043e8f07e524dfcc2450dc71649719a8f3467fb6)
- :apple: Implement show, close and error events for iOS [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/8b5dbb654cbcba7221b36297bd2370456530d0ca)
- :beer: Fire show, close, error and click events from JavaScript [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/1eb096794e02e1a7ca9acb725521342313a41b41)
- :memo: Issue #6: Add github templates [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/162a82d3365c20a438d62f88a0a4cc64b661a3df)
- :wrench: Issue #5: Add pluginpub to package.json [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/e9e789621b12e09e2ffe58386b1d0b0fdcb000e8)
- :apple: implement show and close functionality [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/1f2d380c8d0cd1bd01b1afe3876dc6c99cb097ec)
- :apple: implement requestPermission method [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/e7762331c10727033c1bc6f5539db484874e6d71)
- :penguin: implement requestPermission method [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/19d2f3908462667fcb72ae45d179f2f2b335fabb)
- :wrench: add a gitignore file [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/f1133b13a4f40f3ecc8525a26c99fbbaade93107)
- :memo: update README [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/85bce1324d79f1325396a812319958185b4363ac)
- :penguin: Implementation of show and close functionality [view commit](http://github.com/phonegap/phonegap-plugin-local-notification/commit/f37464874c699a8db7e37d0c4f1bfd8788eea6fd)
undefined

View File

@@ -0,0 +1,20 @@
Copyright 2012-2017 Adobe Systems
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,5 @@
phonegap-plugin-local-notification
------------------------
An implementation of the Web Notifications API for end-user notifications.

View File

@@ -0,0 +1,61 @@
## Functions
<dl>
<dt><a href="#Notification">Notification(title, options)</a></dt>
<dd><p>A global object that lets you interact with the Notification API.</p>
</dd>
</dl>
## Typedefs
<dl>
<dt><a href="#callback">callback</a> : <code>function</code></dt>
<dd><p>A callback to be used when the requestPermission method returns a value.</p>
</dd>
</dl>
<a name="Notification"></a>
## Notification(title, options)
A global object that lets you interact with the Notification API.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| title | <code>string</code> | of the local notification. |
| options | <code>Options</code> | An object containing optional property/value pairs. |
* [Notification(title, options)](#Notification)
* [.requestPermission(callback)](#Notification.requestPermission)
* [.close()](#Notification.close)
<a name="Notification.requestPermission"></a>
### Notification.requestPermission(callback)
requests permission from the user to show a local notification.
**Kind**: static method of [<code>Notification</code>](#Notification)
| Param | Type | Description |
| --- | --- | --- |
| callback | [<code>callback</code>](#callback) | See type definition. |
<a name="Notification.close"></a>
### Notification.close()
closes an open notification.
**Kind**: static method of [<code>Notification</code>](#Notification)
<a name="callback"></a>
## callback : <code>function</code>
A callback to be used when the requestPermission method returns a value.
**Kind**: global typedef
| Param | Type | Description |
| --- | --- | --- |
| permission | <code>string</code> | one of "default", "denied" or "granted" |

View File

@@ -0,0 +1,68 @@
{
"_from": "phonegap-plugin-local-notification",
"_id": "phonegap-plugin-local-notification@1.0.1",
"_inBundle": false,
"_integrity": "sha1-GE9D+1TcARE8y6V5oDrO66eVqds=",
"_location": "/phonegap-plugin-local-notification",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "phonegap-plugin-local-notification",
"name": "phonegap-plugin-local-notification",
"escapedName": "phonegap-plugin-local-notification",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/phonegap-plugin-local-notification/-/phonegap-plugin-local-notification-1.0.1.tgz",
"_shasum": "184f43fb54dc01113ccba579a03aceeba795a9db",
"_spec": "phonegap-plugin-local-notification",
"_where": "/Users/nicco/Documents/git/fight-of-the-mobiles/src/cordova",
"author": {
"name": "Adobe PhoneGap Team"
},
"bugs": {
"url": "http://github.com/phonegap/phonegap-plugin-local-notification/issues"
},
"bundleDependencies": false,
"cordova": {
"id": "phonegap-plugin-local-notification",
"platforms": [
"ios",
"android",
"windows"
]
},
"deprecated": false,
"description": "phonegap-plugin-local-notification ------------------------",
"devDependencies": {
"jasmine-node": "1.14.5",
"jsdoc-to-markdown": "^3.0.0",
"pluginpub": "^0.0.8"
},
"engines": {
"cordova": ">=3.0.0"
},
"homepage": "http://github.com/phonegap/phonegap-plugin-local-notification#readme",
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap"
],
"license": "MIT",
"name": "phonegap-plugin-local-notification",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/phonegap/phonegap-plugin-local-notification.git"
},
"scripts": {
"build": "npm run build:docs && npm test",
"build:docs": "jsdoc2md www/notification.js > docs/api.md",
"test": "jasmine-node --color spec"
},
"version": "1.0.1"
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0" id="phonegap-plugin-local-notification" version="1.0.1">
<name>phonegap-plugin-local-notification</name>
<js-module src="www/notification.js" name="Notification">
<clobbers target="Notification"/>
</js-module>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="LocalNotifications">
<param name="android-package" value="com.adobe.phonegap.notification.LocalNotifications"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.notification.NotificationHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
</config-file>
<source-file src="src/android/LocalNotifications.java" target-dir="src/com/adobe/phonegap/notification"/>
<source-file src="src/android/NotificationHandlerActivity.java" target-dir="src/com/adobe/phonegap/notification"/>
<framework src="com.android.support:support-v13:23+"/>
</platform>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="LocalNotifications">
<param name="ios-package" value="W3CLocalNotifications"/>
</feature>
</config-file>
<header-file src="src/ios/AppDelegate+LocalNotification.h"/>
<header-file src="src/ios/W3CLocalNotifications.h"/>
<source-file src="src/ios/AppDelegate+LocalNotification.m"/>
<source-file src="src/ios/W3CLocalNotifications.m"/>
</platform>
</plugin>

View File

@@ -0,0 +1,130 @@
package com.adobe.phonegap.notification;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
/**
* This class exposes methods in Cordova that can be called from JavaScript.
*/
public class LocalNotifications extends CordovaPlugin {
private static final String TAG = "LocalNotifications";
private static CallbackContext notificationContext;
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback context from which we were invoked.
*/
@SuppressLint("NewApi")
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "in local notifications");
if (action.equals("show")) {
Log.d(TAG, "action show");
notificationContext = callbackContext;
showNotification(args);
PluginResult result = new PluginResult(PluginResult.Status.OK, "show");
result.setKeepCallback(true);
notificationContext.sendPluginResult(result);
} else if (action.equals("close")) {
NotificationManager mNotificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(args.getString(0), 0);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else if (action.equals("requestPermission")) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "granted"));
} else {
Log.d(TAG, "return false");
return false;
}
return true;
}
private void showNotification(JSONArray args) throws JSONException {
// Get args
String title = args.getString(0);
String dir = args.getString(1);
String lang = args.getString(2);
String body = args.getString(3);
String tag = args.getString(4);
String icon = args.getString(5);
Context context = cordova.getActivity();
Intent notificationIntent = new Intent(context, NotificationHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("tag", tag);
int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Build notifications
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(context.getApplicationInfo().icon)
.setContentIntent(contentIntent)
.setAutoCancel(true);
if (icon.startsWith("http://") || icon.startsWith("https://")) {
Bitmap bitmap = getBitmapFromURL(icon);
mBuilder.setLargeIcon(bitmap);
}
// Show notification
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(tag, 0, mBuilder.build());
}
private Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static void fireClickEvent(String tag) {
PluginResult result = new PluginResult(PluginResult.Status.OK, "click");
result.setKeepCallback(true);
notificationContext.sendPluginResult(result);
}
}

View File

@@ -0,0 +1,48 @@
package com.adobe.phonegap.notification;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.support.v4.app.RemoteInput;
public class NotificationHandlerActivity extends Activity {
private static String LOG_TAG = "LocalNotification_PushHandlerActivity";
/*
* this activity will be started if the user touches a notification that we own.
* We send it's data off to the push plugin for processing.
* If needed, we boot up the main activity to kickstart the application.
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(LOG_TAG, "in on create of pushhandleractivity");
Intent intent = getIntent();
String tag = intent.getExtras().getString("tag", "");
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(tag, 0);
LocalNotifications.fireClickEvent(tag);
forceMainActivityReload();
finish();
}
/**
* Forces the main activity to re-launch if it's unloaded.
*/
private void forceMainActivityReload() {
PackageManager pm = getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
startActivity(launchIntent);
}
}

View File

@@ -0,0 +1,12 @@
//
// AppDelegate+LocalNotification.h
//
#import "AppDelegate.h"
@interface AppDelegate (notification)
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification;
@property (nonatomic, retain) NSDictionary *launchNotification;
@end

View File

@@ -0,0 +1,102 @@
//
// AppDelegate+LocalNotification.m
//
#import "AppDelegate+LocalNotification.h"
#import "W3CLocalNotifications.h"
#import <objc/runtime.h>
static char launchNotificationKey;
@implementation AppDelegate (notification)
- (id) getCommandInstance:(NSString*)className
{
return [self.viewController getCommandInstance:className];
}
// its dangerous to override a method from within a category.
// Instead we will use method swizzling. we set this up in the load call.
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(notificationPluginSwizzledInit);
Method original = class_getInstanceMethod(class, originalSelector);
Method swizzled = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzled),
method_getTypeEncoding(swizzled));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(original),
method_getTypeEncoding(original));
} else {
method_exchangeImplementations(original, swizzled);
}
});
}
- (AppDelegate *)notificationPluginSwizzledInit
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(createNotificationChecker:)
name:UIApplicationDidFinishLaunchingNotification
object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(pushPluginOnApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// This actually calls the original init method over in AppDelegate. Equivilent to calling super
// on an overrided method, this is not recursive, although it appears that way. neat huh?
return [self notificationPluginSwizzledInit];
}
// This code will be called immediately after application:didFinishLaunchingWithOptions:. We need
// to process notifications in cold-start situations
- (void)createNotificationChecker:(NSNotification *)notification
{
NSLog(@"createNotificationChecker");
}
- (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {
NSLog(@"active");
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"got local notification");
W3CLocalNotifications *notificationHandler = [self getCommandInstance:@"LocalNotifications"];
[notificationHandler notificationClicked];
}
// The accessors use an Associative Reference since you can't define a iVar in a category
// http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocAssociativeReferences.html
- (NSMutableArray *)launchNotification
{
return objc_getAssociatedObject(self, &launchNotificationKey);
}
- (void)setLaunchNotification:(NSDictionary *)aDictionary
{
objc_setAssociatedObject(self, &launchNotificationKey, aDictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)dealloc
{
self.launchNotification = nil; // clear the association and release the object
}
@end

View File

@@ -0,0 +1,21 @@
//
// W3CLocalNotifications.h
//
#import <Cordova/CDV.h>
#import <Cordova/CDVPlugin.h>
@interface W3CLocalNotifications : CDVPlugin
{
NSDictionary *notificationMessage;
NSString *notificationCallbackId;
}
@property (nonatomic, copy) NSString *callbackId;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
- (void)requestPermission:(CDVInvokedUrlCommand*)command;
- (void)notificationClicked;
@end

View File

@@ -0,0 +1,68 @@
@import UserNotifications;
#import <Cordova/CDV.h>
#import "W3CLocalNotifications.h"
@implementation W3CLocalNotifications : CDVPlugin
@synthesize callbackId;
- (void)show:(CDVInvokedUrlCommand*)command {
self.callbackId = command.callbackId;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = [command.arguments objectAtIndex:0];
content.body = [command.arguments objectAtIndex:3];
NSString *identifier = [command.arguments objectAtIndex:4];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Something went wrong: %@",error);
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} else {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"show"];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}];
}
- (void)close:(CDVInvokedUrlCommand*)command {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
NSArray *identifiers = @[[command.arguments objectAtIndex:0]];
[center removeDeliveredNotificationsWithIdentifiers:identifiers];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)requestPermission:(CDVInvokedUrlCommand*)command {
UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
UNUserNotificationCenter *center = UNUserNotificationCenter.currentNotificationCenter;
[center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"granted"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} else {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"denied"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}];
}
- (void)notificationClicked {
NSLog(@"in plugin, local notification clicked");
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"click"];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
@end

View File

@@ -0,0 +1,105 @@
/* global cordova:false */
/* globals window */
var argscheck = cordova.require('cordova/argscheck'),
exec = cordova.require('cordova/exec'),
utils = cordova.require('cordova/utils');
/**
* @description A global object that lets you interact with the Notification API.
* @global
* @param {!string} title of the local notification.
* @param {?Options} options An object containing optional property/value pairs.
*/
var Notification = function(title, options) {
// require title parameter
if (typeof title === 'undefined') {
throw new Error('The title argument is required.');
}
options = options || {};
var getValue = argscheck.getValue;
this.permission = 'granted';
this.title = getValue(title, '');
this.dir = getValue(options.dir, 'auto');
this.lang = getValue(options.lang, '');
this.body = getValue(options.body, '');
this.tag = getValue(options.tag, '');
this.icon = getValue(options.icon, '');
this.onclick = function() {};
this.onshow = function() {};
this.onerror = function() {};
this.onclose = function() {};
// triggered on click, show, error and close
var that = this;
var success = function(result) {
if (!result) {
return;
}
if (result === 'show') {
that.onshow();
} else if (result === 'click') {
that.onclick();
}
};
var failure = function() {
that.onerror();
};
exec(success, failure, 'LocalNotifications', 'show', [this.title, this.dir, this.lang, this.body, this.tag, this.icon]);
};
/**
* @description requests permission from the user to show a local notification.
* @function requestPermission
* @memberof Notification
* @param {!callback} callback - See type definition.
*/
Notification.requestPermission = function(callback) {
if (!callback) { callback = function() {}; }
if (typeof callback !== 'function') {
console.log('Notification.requestPermission failure: callback parameter not a function');
return;
}
exec(callback, function() {
console.log('requestPermission error');
}, 'LocalNotifications', 'requestPermission', []);
};
/**
* @description closes an open notification.
* @function close
* @memberof Notification
*/
Notification.prototype.close = function() {
var that = this;
exec(function() {
that.onclose();
}, function() {
that.onerror();
}, 'LocalNotifications', 'close', [this.tag]);
};
/**
* @description A callback to be used when the requestPermission method returns a value.
*
* @callback callback
* @param {string} permission - one of "default", "denied" or "granted"
*/
/*
* @typedef {Object} Options - An object for configuring Notification behavior.
* @property {string} [dir='auto'] - Sets the direction of the notification. One of "auto", "ltr" or "rtl"
* @property {string} [lang=''] - Sets the language of the notification
* @property {string} [body=''] - Sets the body of the notification
* @property {string} [tag=''] - Sets the identifying tag of the notification
* @property {string} [icon=''] - Sets the icon of the notification
*/
module.exports = Notification;