Commit 13af9eab by Sebastián Katzer

Update project and plugin

parent c4a5a7cb
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key> <key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/> <false/>
<key>IDESourceControlProjectIdentifier</key> <key>IDESourceControlProjectIdentifier</key>
<string>AFAFE068-92EA-475E-8783-6E5FC17A7188</string> <string>A63F5FF5-C059-403D-81B9-E740110FFC25</string>
<key>IDESourceControlProjectName</key> <key>IDESourceControlProjectName</key>
<string>NotificationExample</string> <string>NotificationExample</string>
<key>IDESourceControlProjectOriginsDictionary</key> <key>IDESourceControlProjectOriginsDictionary</key>
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#import <Cordova/CDVViewController.h> #import <Cordova/CDVViewController.h>
extern NSString* const UIApplicationRegisterUserNotificationSettings;
@interface AppDelegate : NSObject <UIApplicationDelegate>{} @interface AppDelegate : NSObject <UIApplicationDelegate>{}
// invoke string is passed to your app on launch, this is only valid if you // invoke string is passed to your app on launch, this is only valid if you
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#import <Cordova/CDVPlugin.h> #import <Cordova/CDVPlugin.h>
NSString* const UIApplicationRegisterUserNotificationSettings = @"UIApplicationRegisterUserNotificationSettings";
@implementation AppDelegate @implementation AppDelegate
@synthesize window, viewController; @synthesize window, viewController;
...@@ -148,4 +150,18 @@ ...@@ -148,4 +150,18 @@
[[NSURLCache sharedURLCache] removeAllCachedResponses]; [[NSURLCache sharedURLCache] removeAllCachedResponses];
} }
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- (void) application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings
{
NSNotificationCenter* center = [NSNotificationCenter
defaultCenter];
// re-post (broadcast)
[center postNotificationName:UIApplicationRegisterUserNotificationSettings
object:settings];
}
#endif
@end @end
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</dict> </dict>
</dict> </dict>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>de.appplant.cordova.plugin.local-notification.example</string> <string>de.appplant.localnotification.example</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "AppDelegate.h"
#import "APPLocalNotification.h" #import "APPLocalNotification.h"
#import "APPLocalNotificationOptions.h" #import "APPLocalNotificationOptions.h"
#import "AppDelegate+APPLocalNotification.h"
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h"
......
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate.h"
#import <Availability.h>
extern NSString* const UIApplicationRegisterUserNotificationSettings;
@interface AppDelegate (APPLocalNotification)
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// Tells the delegate what types of notifications may be used
- (void) application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings;
#endif
@end
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate+APPLocalNotification.h"
#import <Availability.h>
NSString* const UIApplicationRegisterUserNotificationSettings = @"UIApplicationRegisterUserNotificationSettings";
@implementation AppDelegate (APPLocalNotification)
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
/**
* Tells the delegate what types of notifications may be used
* to get the user’s attention.
*/
- (void) application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings
{
NSNotificationCenter* center = [NSNotificationCenter
defaultCenter];
// re-post (broadcast)
[center postNotificationName:UIApplicationRegisterUserNotificationSettings
object:settings];
}
#endif
@end
...@@ -62,7 +62,10 @@ ...@@ -62,7 +62,10 @@
UIUserNotificationType types; UIUserNotificationType types;
UIUserNotificationSettings *settings; UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound; settings = [[UIApplication sharedApplication]
currentUserNotificationSettings];
types = settings.types|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil]; categories:nil];
......
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<widget id="de.appplant.cordova.plugin.local-notification.example" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <widget id="de.appplant.localnotification.example" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="AllowInlineMediaPlayback" value="false" /> <preference name="AllowInlineMediaPlayback" value="false" />
<preference name="BackupWebStorage" value="cloud" /> <preference name="BackupWebStorage" value="cloud" />
<preference name="DisallowOverscroll" value="false" /> <preference name="DisallowOverscroll" value="false" />
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
</author> </author>
<content src="index.html" /> <content src="index.html" />
<access origin="*" /> <access origin="*" />
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
<feature name="Device"> <feature name="Device">
<param name="ios-package" value="CDVDevice" /> <param name="ios-package" value="CDVDevice" />
</feature> </feature>
...@@ -33,4 +30,7 @@ ...@@ -33,4 +30,7 @@
<param name="ios-package" onload="true" value="APPLocalNotification" /> <param name="ios-package" onload="true" value="APPLocalNotification" />
<param name="onload" value="true" /> <param name="onload" value="true" />
</feature> </feature>
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
</widget> </widget>
cordova.define('cordova/plugin_list', function(require, exports, module) { cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [ module.exports = [
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js", "file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification", "id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [ "clobbers": [
...@@ -36,6 +25,17 @@ module.exports = [ ...@@ -36,6 +25,17 @@ module.exports = [
] ]
}, },
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/org.apache.cordova.device/www/device.js", "file": "plugins/org.apache.cordova.device/www/device.js",
"id": "org.apache.cordova.device.device", "id": "org.apache.cordova.device.device",
"clobbers": [ "clobbers": [
...@@ -46,8 +46,8 @@ module.exports = [ ...@@ -46,8 +46,8 @@ module.exports = [
module.exports.metadata = module.exports.metadata =
// TOP OF METADATA // TOP OF METADATA
{ {
"nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev", "de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3",
"org.apache.cordova.device": "0.3.0" "org.apache.cordova.device": "0.3.0"
} }
// BOTTOM OF METADATA // BOTTOM OF METADATA
......
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ReferenceCachePath>C:\Users\sebastian\AppData\Local\Temp\yxmokjnx_CordovaApp.Phone_refcache</ReferenceCachePath> <ReferenceCachePath>C:\Users\sebastian\AppData\Local\Temp\yxmokjnx_CordovaApp.Phone_refcache</ReferenceCachePath>
<AutoRefresh>true</AutoRefresh>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
\ No newline at end of file
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
</Resources> </Resources>
<Applications> <Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html"> <Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true"> <m3:VisualElements ToastCapable="true" DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png"> <m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles> <m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" /> <m3:ShowOn Tile="square150x150Logo" />
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</Resources> </Resources>
<Applications> <Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html"> <Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true"> <m3:VisualElements ToastCapable="true" DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png"> <m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles> <m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" /> <m3:ShowOn Tile="square150x150Logo" />
......
cordova.define('cordova/plugin_list', function(require, exports, module) { cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [ module.exports = [
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js", "file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification", "id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [ "clobbers": [
...@@ -46,17 +57,6 @@ module.exports = [ ...@@ -46,17 +57,6 @@ module.exports = [
] ]
}, },
{ {
"file": "plugins/nl.x-services.plugins.toast/www/Toast.js",
"id": "nl.x-services.plugins.toast.Toast",
"clobbers": [
"window.plugins.toast"
]
},
{
"file": "plugins/nl.x-services.plugins.toast/test/tests.js",
"id": "nl.x-services.plugins.toast.tests"
},
{
"file": "plugins/org.apache.cordova.device/www/device.js", "file": "plugins/org.apache.cordova.device/www/device.js",
"id": "org.apache.cordova.device.device", "id": "org.apache.cordova.device.device",
"clobbers": [ "clobbers": [
...@@ -74,8 +74,8 @@ module.exports = [ ...@@ -74,8 +74,8 @@ module.exports = [
module.exports.metadata = module.exports.metadata =
// TOP OF METADATA // TOP OF METADATA
{ {
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3", "nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"org.apache.cordova.device": "0.3.0" "org.apache.cordova.device": "0.3.0"
} }
// BOTTOM OF METADATA // BOTTOM OF METADATA
......
...@@ -32,14 +32,12 @@ exports.core = { ...@@ -32,14 +32,12 @@ exports.core = {
*/ */
deviceready: function () { deviceready: function () {
var plugin = cordova.plugins.notification.local, var plugin = cordova.plugins.notification.local,
args; events = this.eventQueue;
this.isReady = true; this.isReady = true;
for (var i = 0; i < this.eventQueue.length; i++) { for (var i = 0; i < events.length; i++) {
args = this.eventQueue[i]; plugin.fireEvent.apply(plugin, events[i]);
plugin.fireEvent.apply(plugin, args);
} }
this.eventQueue = []; this.eventQueue = [];
...@@ -64,10 +62,8 @@ exports.core = { ...@@ -64,10 +62,8 @@ exports.core = {
notification = this.build(options); notification = this.build(options);
this.cancelLocalNotification(options.id); this.cancelLocalNotification(options.id);
this.scheduleLocalNotification(notification, options); this.scheduleLocalNotification(notification, options);
this.scheduleBackupNotification(notification, options); this.scheduleBackupNotification(notification, options);
this.fireEvent('schedule', options); this.fireEvent('schedule', options);
this.callOnTrigger(options, triggerFn); this.callOnTrigger(options, triggerFn);
} }
...@@ -147,18 +143,6 @@ exports.core = { ...@@ -147,18 +143,6 @@ exports.core = {
}, },
/** /**
* Updates a single local notification.
*
* @param {Object} notification
* The local notification
* @param {Object} updates
* Updated properties
*/
updateLocalNotification: function (notification, updates) {
},
/**
* Updates existing notifications specified by IDs in options. * Updates existing notifications specified by IDs in options.
* *
* @param {Object[]} notifications * @param {Object[]} notifications
...@@ -175,6 +159,23 @@ exports.core = { ...@@ -175,6 +159,23 @@ exports.core = {
}, },
/** /**
* Updates a single local notification.
*
* @param {Object} notification
* The local notification
* @param {Object} updates
* Updated properties
*/
updateLocalNotification: function (notification, updates) {
for (var key in updates) {
notification[key] = updates[key];
}
this.cancelLocalNotification(notification.id);
this.scheduleLocalNotification(notification);
},
/**
* Clears the specified notifications. * Clears the specified notifications.
* *
* @param {int[]} ids * @param {int[]} ids
...@@ -182,9 +183,10 @@ exports.core = { ...@@ -182,9 +183,10 @@ exports.core = {
*/ */
clear: function (ids) { clear: function (ids) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
var notification = this.getAll([id])[0]; var id = ids[i],
notification = this.getAll([id])[0];
this.clearLocalNotification(ids[i]); this.clearLocalNotification(id);
this.fireEvent('clear', notification); this.fireEvent('clear', notification);
} }
}, },
...@@ -196,8 +198,13 @@ exports.core = { ...@@ -196,8 +198,13 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
clearLocalNotification: function (id) { clearLocalNotification: function (id) {
var notification = this.getAll([id])[0];
this.getToastHistory().remove('Toast' + id); this.getToastHistory().remove('Toast' + id);
if (this.isRepeating(notification))
return;
if (this.isTriggered(id) && !this.isScheduled(id)) { if (this.isTriggered(id) && !this.isScheduled(id)) {
this.cancelLocalNotification(id); this.cancelLocalNotification(id);
} }
...@@ -225,7 +232,8 @@ exports.core = { ...@@ -225,7 +232,8 @@ exports.core = {
*/ */
cancel: function (ids) { cancel: function (ids) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
var notification = this.getAll([id])[0]; var id = ids[i],
notification = this.getAll([id])[0];
this.cancelLocalNotification(ids[i]); this.cancelLocalNotification(ids[i]);
this.fireEvent('cancel', notification); this.fireEvent('cancel', notification);
...@@ -275,7 +283,7 @@ exports.core = { ...@@ -275,7 +283,7 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isPresent: function (id) { isPresent: function (id) {
return this.getAllIds().indexOf(id) > -1; return !!this.findToastById(id);
}, },
/** /**
...@@ -285,7 +293,9 @@ exports.core = { ...@@ -285,7 +293,9 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isScheduled: function (id) { isScheduled: function (id) {
return this.getScheduledIds().indexOf(id) > -1; var toast = this.findToastById(id);
return toast && this.isToastScheduled(toast);
}, },
/** /**
...@@ -295,7 +305,9 @@ exports.core = { ...@@ -295,7 +305,9 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isTriggered: function (id) { isTriggered: function (id) {
return this.getTriggeredIds().indexOf(id) > -1; var toast = this.findToastById(id);
return toast && this.isToastTriggered(toast);
}, },
/** /**
...@@ -365,7 +377,7 @@ exports.core = { ...@@ -365,7 +377,7 @@ exports.core = {
var toasts = this.getScheduledToasts(), var toasts = this.getScheduledToasts(),
notifications = []; notifications = [];
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
...@@ -392,7 +404,7 @@ exports.core = { ...@@ -392,7 +404,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getScheduled: function (ids) { getScheduled: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
...@@ -407,7 +419,7 @@ exports.core = { ...@@ -407,7 +419,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getTriggered: function (ids) { getTriggered: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
......
...@@ -19,6 +19,9 @@ cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification. ...@@ -19,6 +19,9 @@ cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification.
under the License. under the License.
*/ */
var channel = require('cordova/channel');
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core; exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core;
...@@ -66,6 +69,18 @@ exports.getRepeatInterval = function (every) { ...@@ -66,6 +69,18 @@ exports.getRepeatInterval = function (every) {
}; };
/** /**
* If the notification is repeating.
*
* @param {Object} notification
* Local notification object
*
* @return Boolean
*/
exports.isRepeating = function (notification) {
return this.getRepeatInterval(notification.every) !== 0;
};
/**
* Parses sound file path. * Parses sound file path.
* *
* @param {String} path * @param {String} path
...@@ -87,76 +102,76 @@ exports.parseSound = function (path) { ...@@ -87,76 +102,76 @@ exports.parseSound = function (path) {
return audio; return audio;
}; };
/** /**
* Builds the xml payload for a local notification based on its options. * Builds the xml payload for a local notification based on its options.
* *
* @param {Object} options * @param {Object} options
* Local notification properties * Local notification properties
* *
* @return Windows.Data.Xml.Dom.XmlDocument * @return Windows.Data.Xml.Dom.XmlDocument
*/ */
exports.build = function (options) { exports.build = function (options) {
var template = this.buildToastTemplate(options), var template = this.buildToastTemplate(options),
notification = new Windows.Data.Xml.Dom.XmlDocument(); notification = new Windows.Data.Xml.Dom.XmlDocument();
try { try {
notification.loadXml(template); notification.loadXml(template);
} catch (e) { } catch (e) {
console.error( console.error(
'LocalNotification#schedule', 'LocalNotification#schedule',
'Error loading the xml, check for invalid characters.'); 'Error loading the xml, check for invalid characters.');
} }
// Launch Attribute to enable onClick event // Launch Attribute to enable onClick event
var launchAttr = notification.createAttribute('launch'), var launchAttr = notification.createAttribute('launch'),
toastNode = notification.selectSingleNode('/toast'); toastNode = notification.selectSingleNode('/toast');
launchAttr.value = options.id.toString(); launchAttr.value = options.id.toString();
toastNode.attributes.setNamedItem(launchAttr); toastNode.attributes.setNamedItem(launchAttr);
return notification; return notification;
}; };
/** /**
* Builds the toast template with the right style depend on the options. * Builds the toast template with the right style depend on the options.
* *
* @param {Object} options * @param {Object} options
* Local notification properties * Local notification properties
* *
* @return String * @return String
*/ */
exports.buildToastTemplate = function (options) { exports.buildToastTemplate = function (options) {
var title = options.title, var title = options.title,
message = options.text || '', message = options.text || '',
json = JSON.stringify(options), json = JSON.stringify(options),
sound = ''; sound = '';
if (options.sound && options.sound !== '') { if (options.sound && options.sound !== '') {
sound = this.parseSound(options.sound); sound = this.parseSound(options.sound);
} }
if (title && title !== '') { if (title && title !== '') {
return "<toast>" + return "<toast>" +
"<visual>" + "<visual>" +
"<binding template='ToastText02'>" + "<binding template='ToastText02'>" +
"<text id='1'>" + title + "</text>" + "<text id='1'>" + title + "</text>" +
"<text id='2'>" + message + "</text>" + "<text id='2'>" + message + "</text>" +
"</binding>" + "</binding>" +
"</visual>" + "</visual>" +
sound + sound +
"<json>" + json + "</json>" + "<json>" + json + "</json>" +
"</toast>"; "</toast>";
} else { } else {
return "<toast>" + return "<toast>" +
"<visual>" + "<visual>" +
"<binding template='ToastText01'>" + "<binding template='ToastText01'>" +
"<text id='1'>" + message + "</text>" + "<text id='1'>" + message + "</text>" +
"</binding>" + "</binding>" +
"</visual>" + "</visual>" +
sound + sound +
"<json>" + json + "</json>" + "<json>" + json + "</json>" +
"</toast>"; "</toast>";
} }
}; };
/** /**
...@@ -240,6 +255,9 @@ exports.isToastTriggered = function (toast) { ...@@ -240,6 +255,9 @@ exports.isToastTriggered = function (toast) {
notification = this.getAll(id)[0]; notification = this.getAll(id)[0];
fireDate = new Date((notification.at) * 1000); fireDate = new Date((notification.at) * 1000);
if (this.isRepeating(notification))
return false;
return fireDate <= new Date(); return fireDate <= new Date();
}; };
...@@ -289,6 +307,20 @@ exports.callOnTrigger = function (notification, callback) { ...@@ -289,6 +307,20 @@ exports.callOnTrigger = function (notification, callback) {
}; };
/** /**
* Sets trigger event for all scheduled local notification.
*
* @param {Function} callback
* Callback function
*/
exports.callOnTriggerForScheduled = function (callback) {
var notifications = this.getScheduled();
for (var i = 0; i < notifications.length; i++) {
this.callOnTrigger(notifications[i], callback);
}
};
/**
* The application state - background or foreground. * The application state - background or foreground.
* *
* @return String * @return String
...@@ -328,6 +360,31 @@ exports.fireEvent = function (event, notification) { ...@@ -328,6 +360,31 @@ exports.fireEvent = function (event, notification) {
* LIFE CYCLE * * LIFE CYCLE *
**************/ **************/
// Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () {
// Register trigger handler for each scheduled notification
exports.callOnTriggerForScheduled(function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
});
});
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
var repeating = exports.isRepeating(notification);
exports.fireEvent('click', notification);
exports.fireEvent(repeating ? 'clear' : 'cancel', notification);
}, false);
// App is running in background // App is running in background
document.addEventListener('pause', function () { document.addEventListener('pause', function () {
exports.isInBackground = true; exports.isInBackground = true;
...@@ -343,16 +400,4 @@ document.addEventListener('deviceready', function () { ...@@ -343,16 +400,4 @@ document.addEventListener('deviceready', function () {
exports.isInBackground = false; exports.isInBackground = false;
}, false); }, false);
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
exports.fireEvent('click', notification);
}, false);
}); });
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
<!-- info --> <!-- info -->
<info> <info>
Your support is needed. If you use the plugin please support us in order to ensure further development. Your support is needed. If you use the local-notification plugin please support us in order to ensure further development.
https://github.com/katzer/cordova-plugin-local-notifications/tree/example#how-can-i-support-the-further-development https://github.com/katzer/cordova-plugin-local-notifications#supporting
Thank you! Thank you!
</info> </info>
...@@ -59,9 +59,6 @@ ...@@ -59,9 +59,6 @@
</feature> </feature>
</config-file> </config-file>
<header-file src="src/ios/AppDelegate+APPLocalNotification.h" />
<source-file src="src/ios/AppDelegate+APPLocalNotification.m" />
<header-file src="src/ios/APPLocalNotification.h" /> <header-file src="src/ios/APPLocalNotification.h" />
<source-file src="src/ios/APPLocalNotification.m" /> <source-file src="src/ios/APPLocalNotification.m" />
...@@ -74,6 +71,14 @@ ...@@ -74,6 +71,14 @@
<header-file src="src/ios/UILocalNotification+APPLocalNotification.h" /> <header-file src="src/ios/UILocalNotification+APPLocalNotification.h" />
<source-file src="src/ios/UILocalNotification+APPLocalNotification.m" /> <source-file src="src/ios/UILocalNotification+APPLocalNotification.m" />
<hook
type="after_platform_add"
src="scripts/ios/didRegisterUserNotificationSettings.js" />
<hook
type="after_plugin_install"
src="scripts/ios/didRegisterUserNotificationSettings.js" />
</platform> </platform>
<!-- android --> <!-- android -->
......
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
// Hook inserts the UIApplicationRegisterUserNotificationSettings constant
// and the didRegisterUserNotificationSettings method to AppDelegate.
var fs = require('fs'),
path = require('path'),
rootdir = process.argv[2];
if (!rootdir)
return;
module.exports = function (context) {
var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'),
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
platforms = context.requireCordovaModule('cordova-lib/src/cordova/platforms'),
projectRoot = cordova_util.isCordova(),
xml = cordova_util.projectConfig(projectRoot),
cfg = new ConfigParser(xml);
/**
* The absolute path for the file.
*
* @param {String} platform
* The name of the platform like 'ios'.
* @param {String} relPath
* The relative path from the platform root directory.
*
* @return String
*/
function getAbsPath(platform, relPath) {
var platform_path = path.join(projectRoot, 'platforms', platform),
parser = new platforms[platform].parser(platform_path);
return path.join(parser.cordovaproj, relPath);
}
/**
* Replaces a string with another one in a file.
*
* @param {String} path
* Absolute or relative file path from cordova root project.
* @param {String} to_replace
* The string to replace.
* @param {String}
* The string to replace with.
*/
function replace (path, to_replace, replace_with) {
var data = fs.readFileSync(path, 'utf8'),
result;
if (data.indexOf(replace_with) > -1)
return;
result = data.replace(new RegExp(to_replace, 'g'), replace_with);
fs.writeFileSync(path, result, 'utf8');
}
// Absolute paths for AppDelegate's header and member
var h_path = getAbsPath('ios', 'Classes/AppDelegate.h'),
m_path = getAbsPath('ios', 'Classes/AppDelegate.m');
// Decleration of UIApplicationRegisterUserNotificationSettings
var h_UIApplicationRegisterUserNotificationSettings =
"extern NSString* const UIApplicationRegisterUserNotificationSettings;\n";
// Implementation of UIApplicationRegisterUserNotificationSettings
var m_UIApplicationRegisterUserNotificationSettings =
"NSString* const UIApplicationRegisterUserNotificationSettings = @\"UIApplicationRegisterUserNotificationSettings\";\n";
// Implementation for didRegisterUserNotificationSettings
var didRegisterUserNotificationSettings =
"#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000\n" +
"\n" +
"- (void) application:(UIApplication*)application\n" +
" didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings\n" +
"{\n" +
" NSNotificationCenter* center = [NSNotificationCenter\n" +
" defaultCenter];\n" +
"\n" +
" // re-post (broadcast)\n" +
" [center postNotificationName:UIApplicationRegisterUserNotificationSettings\n" +
" object:settings];\n" +
"}\n" +
"#endif\n";
// Inserts the constant decleration
replace(h_path, '@interface AppDelegate', h_UIApplicationRegisterUserNotificationSettings + "\n@interface AppDelegate");
// Inserts the constant implementation
replace(m_path, '@implementation AppDelegate', m_UIApplicationRegisterUserNotificationSettings + "\n@implementation AppDelegate");
// Inserts the didRegisterUserNotificationSettings implementation
replace(m_path, '@end', didRegisterUserNotificationSettings + "\n@end");
};
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "AppDelegate.h"
#import "APPLocalNotification.h" #import "APPLocalNotification.h"
#import "APPLocalNotificationOptions.h" #import "APPLocalNotificationOptions.h"
#import "AppDelegate+APPLocalNotification.h"
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h"
......
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate.h"
#import <Availability.h>
extern NSString* const UIApplicationRegisterUserNotificationSettings;
@interface AppDelegate (APPLocalNotification)
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// Tells the delegate what types of notifications may be used
- (void) application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings;
#endif
@end
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate+APPLocalNotification.h"
#import <Availability.h>
NSString* const UIApplicationRegisterUserNotificationSettings = @"UIApplicationRegisterUserNotificationSettings";
@implementation AppDelegate (APPLocalNotification)
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
/**
* Tells the delegate what types of notifications may be used
* to get the user’s attention.
*/
- (void) application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings
{
NSNotificationCenter* center = [NSNotificationCenter
defaultCenter];
// re-post (broadcast)
[center postNotificationName:UIApplicationRegisterUserNotificationSettings
object:settings];
}
#endif
@end
...@@ -62,7 +62,10 @@ ...@@ -62,7 +62,10 @@
UIUserNotificationType types; UIUserNotificationType types;
UIUserNotificationSettings *settings; UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound; settings = [[UIApplication sharedApplication]
currentUserNotificationSettings];
types = settings.types|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil]; categories:nil];
......
...@@ -32,14 +32,12 @@ exports.core = { ...@@ -32,14 +32,12 @@ exports.core = {
*/ */
deviceready: function () { deviceready: function () {
var plugin = cordova.plugins.notification.local, var plugin = cordova.plugins.notification.local,
args; events = this.eventQueue;
this.isReady = true; this.isReady = true;
for (var i = 0; i < this.eventQueue.length; i++) { for (var i = 0; i < events.length; i++) {
args = this.eventQueue[i]; plugin.fireEvent.apply(plugin, events[i]);
plugin.fireEvent.apply(plugin, args);
} }
this.eventQueue = []; this.eventQueue = [];
...@@ -54,8 +52,8 @@ exports.core = { ...@@ -54,8 +52,8 @@ exports.core = {
* 'schedule' or 'update' * 'schedule' or 'update'
*/ */
schedule: function (notifications) { schedule: function (notifications) {
var triggerFn = function (notification) { var triggerFn = function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification); this.fireEvent('trigger', notification);
}; };
...@@ -64,10 +62,8 @@ exports.core = { ...@@ -64,10 +62,8 @@ exports.core = {
notification = this.build(options); notification = this.build(options);
this.cancelLocalNotification(options.id); this.cancelLocalNotification(options.id);
this.scheduleLocalNotification(notification, options); this.scheduleLocalNotification(notification, options);
this.scheduleBackupNotification(notification, options); this.scheduleBackupNotification(notification, options);
this.fireEvent('schedule', options); this.fireEvent('schedule', options);
this.callOnTrigger(options, triggerFn); this.callOnTrigger(options, triggerFn);
} }
...@@ -128,15 +124,22 @@ exports.core = { ...@@ -128,15 +124,22 @@ exports.core = {
}, },
/** /**
* Updates a single local notification. * Updates the badge number of the active tile.
* *
* @param {Object} notification * @param {Number} badge
* The local notification * The badge number. Zero will clean the badge.
* @param {Object} updates
* Updated properties
*/ */
updateLocalNotification: function (notification, updates) { updateBadge: function (badge) {
var notifications = Windows.UI.Notifications,
type = notifications.BadgeTemplateType.badgeNumber,
xml = notifications.BadgeUpdateManager.getTemplateContent(type),
attrs = xml.getElementsByTagName('badge'),
notification = new notifications.BadgeNotification(xml);
attrs[0].setAttribute('value', badge);
notifications.BadgeUpdateManager.createBadgeUpdaterForApplication()
.update(notification);
}, },
/** /**
...@@ -156,6 +159,23 @@ exports.core = { ...@@ -156,6 +159,23 @@ exports.core = {
}, },
/** /**
* Updates a single local notification.
*
* @param {Object} notification
* The local notification
* @param {Object} updates
* Updated properties
*/
updateLocalNotification: function (notification, updates) {
for (var key in updates) {
notification[key] = updates[key];
}
this.cancelLocalNotification(notification.id);
this.scheduleLocalNotification(notification);
},
/**
* Clears the specified notifications. * Clears the specified notifications.
* *
* @param {int[]} ids * @param {int[]} ids
...@@ -163,9 +183,10 @@ exports.core = { ...@@ -163,9 +183,10 @@ exports.core = {
*/ */
clear: function (ids) { clear: function (ids) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
var notification = this.getAll([id])[0]; var id = ids[i],
notification = this.getAll([id])[0];
this.clearLocalNotification(ids[i]); this.clearLocalNotification(id);
this.fireEvent('clear', notification); this.fireEvent('clear', notification);
} }
}, },
...@@ -177,8 +198,13 @@ exports.core = { ...@@ -177,8 +198,13 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
clearLocalNotification: function (id) { clearLocalNotification: function (id) {
var notification = this.getAll([id])[0];
this.getToastHistory().remove('Toast' + id); this.getToastHistory().remove('Toast' + id);
if (this.isRepeating(notification))
return;
if (this.isTriggered(id) && !this.isScheduled(id)) { if (this.isTriggered(id) && !this.isScheduled(id)) {
this.cancelLocalNotification(id); this.cancelLocalNotification(id);
} }
...@@ -206,7 +232,8 @@ exports.core = { ...@@ -206,7 +232,8 @@ exports.core = {
*/ */
cancel: function (ids) { cancel: function (ids) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
var notification = this.getAll([id])[0]; var id = ids[i],
notification = this.getAll([id])[0];
this.cancelLocalNotification(ids[i]); this.cancelLocalNotification(ids[i]);
this.fireEvent('cancel', notification); this.fireEvent('cancel', notification);
...@@ -256,7 +283,7 @@ exports.core = { ...@@ -256,7 +283,7 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isPresent: function (id) { isPresent: function (id) {
return this.getAllIds().indexOf(id) > -1; return !!this.findToastById(id);
}, },
/** /**
...@@ -266,7 +293,9 @@ exports.core = { ...@@ -266,7 +293,9 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isScheduled: function (id) { isScheduled: function (id) {
return this.getScheduledIds().indexOf(id) > -1; var toast = this.findToastById(id);
return toast && this.isToastScheduled(toast);
}, },
/** /**
...@@ -276,7 +305,9 @@ exports.core = { ...@@ -276,7 +305,9 @@ exports.core = {
* Local notification ID * Local notification ID
*/ */
isTriggered: function (id) { isTriggered: function (id) {
return this.getTriggeredIds().indexOf(id) > -1; var toast = this.findToastById(id);
return toast && this.isToastTriggered(toast);
}, },
/** /**
...@@ -346,8 +377,8 @@ exports.core = { ...@@ -346,8 +377,8 @@ exports.core = {
var toasts = this.getScheduledToasts(), var toasts = this.getScheduledToasts(),
notifications = []; notifications = [];
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = getAllIds(); ids = this.getAllIds();
} }
for (var index = 0; index < ids.length; index++) { for (var index = 0; index < ids.length; index++) {
...@@ -373,7 +404,7 @@ exports.core = { ...@@ -373,7 +404,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getScheduled: function (ids) { getScheduled: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
...@@ -388,7 +419,7 @@ exports.core = { ...@@ -388,7 +419,7 @@ exports.core = {
* List of local notification IDs * List of local notification IDs
*/ */
getTriggered: function (ids) { getTriggered: function (ids) {
if (ids.length === 0) { if (!ids || ids.length === 0) {
ids = this.getAllIds(); ids = this.getAllIds();
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
under the License. under the License.
*/ */
var channel = require('cordova/channel');
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core; exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core;
...@@ -66,6 +69,18 @@ exports.getRepeatInterval = function (every) { ...@@ -66,6 +69,18 @@ exports.getRepeatInterval = function (every) {
}; };
/** /**
* If the notification is repeating.
*
* @param {Object} notification
* Local notification object
*
* @return Boolean
*/
exports.isRepeating = function (notification) {
return this.getRepeatInterval(notification.every) !== 0;
};
/**
* Parses sound file path. * Parses sound file path.
* *
* @param {String} path * @param {String} path
...@@ -93,38 +108,14 @@ exports.parseSound = function (path) { ...@@ -93,38 +108,14 @@ exports.parseSound = function (path) {
* @param {Object} options * @param {Object} options
* Local notification properties * Local notification properties
* *
* @return {String} * @return Windows.Data.Xml.Dom.XmlDocument
* Windows.Data.Xml.Dom.XmlDocument
*/ */
exports.build = function (options) { exports.build = function (options) {
var title = options.title, var template = this.buildToastTemplate(options),
message = options.text || '', notification = new Windows.Data.Xml.Dom.XmlDocument();
sound = '';
if (!title || title === '') {
title = 'Notification';
}
if (options.sound) {
sound = this.parseSound(options.sound);
}
var payload =
"<toast> " +
"<visual version='2'>" +
"<binding template='ToastText02'>" +
"<text id='2'>" + message + "</text>" +
"<text id='1'>" + title + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + JSON.stringify(options) + "</json>" +
"</toast>";
var notification = new Windows.Data.Xml.Dom.XmlDocument();
try { try {
notification.loadXml(payload); notification.loadXml(template);
} catch (e) { } catch (e) {
console.error( console.error(
'LocalNotification#schedule', 'LocalNotification#schedule',
...@@ -142,6 +133,48 @@ exports.build = function (options) { ...@@ -142,6 +133,48 @@ exports.build = function (options) {
}; };
/** /**
* Builds the toast template with the right style depend on the options.
*
* @param {Object} options
* Local notification properties
*
* @return String
*/
exports.buildToastTemplate = function (options) {
var title = options.title,
message = options.text || '',
json = JSON.stringify(options),
sound = '';
if (options.sound && options.sound !== '') {
sound = this.parseSound(options.sound);
}
if (title && title !== '') {
return "<toast>" +
"<visual>" +
"<binding template='ToastText02'>" +
"<text id='1'>" + title + "</text>" +
"<text id='2'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
} else {
return "<toast>" +
"<visual>" +
"<binding template='ToastText01'>" +
"<text id='1'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
}
};
/**
* Short-hand method for the toast notification history. * Short-hand method for the toast notification history.
*/ */
exports.getToastHistory = function () { exports.getToastHistory = function () {
...@@ -222,6 +255,9 @@ exports.isToastTriggered = function (toast) { ...@@ -222,6 +255,9 @@ exports.isToastTriggered = function (toast) {
notification = this.getAll(id)[0]; notification = this.getAll(id)[0];
fireDate = new Date((notification.at) * 1000); fireDate = new Date((notification.at) * 1000);
if (this.isRepeating(notification))
return false;
return fireDate <= new Date(); return fireDate <= new Date();
}; };
...@@ -271,6 +307,20 @@ exports.callOnTrigger = function (notification, callback) { ...@@ -271,6 +307,20 @@ exports.callOnTrigger = function (notification, callback) {
}; };
/** /**
* Sets trigger event for all scheduled local notification.
*
* @param {Function} callback
* Callback function
*/
exports.callOnTriggerForScheduled = function (callback) {
var notifications = this.getScheduled();
for (var i = 0; i < notifications.length; i++) {
this.callOnTrigger(notifications[i], callback);
}
};
/**
* The application state - background or foreground. * The application state - background or foreground.
* *
* @return String * @return String
...@@ -310,6 +360,31 @@ exports.fireEvent = function (event, notification) { ...@@ -310,6 +360,31 @@ exports.fireEvent = function (event, notification) {
* LIFE CYCLE * * LIFE CYCLE *
**************/ **************/
// Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () {
// Register trigger handler for each scheduled notification
exports.callOnTriggerForScheduled(function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
});
});
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
var repeating = exports.isRepeating(notification);
exports.fireEvent('click', notification);
exports.fireEvent(repeating ? 'clear' : 'cancel', notification);
}, false);
// App is running in background // App is running in background
document.addEventListener('pause', function () { document.addEventListener('pause', function () {
exports.isInBackground = true; exports.isInBackground = true;
...@@ -324,15 +399,3 @@ document.addEventListener('resume', function () { ...@@ -324,15 +399,3 @@ document.addEventListener('resume', function () {
document.addEventListener('deviceready', function () { document.addEventListener('deviceready', function () {
exports.isInBackground = false; exports.isInBackground = false;
}, false); }, false);
// Handle onclick event
WinJS.Application.addEventListener('activated', function (args) {
var id = args.detail.arguments,
notification = exports.getAll([id])[0];
if (!notification)
return;
exports.clearLocalNotification(id);
exports.fireEvent('click', notification);
}, false);
...@@ -9,15 +9,15 @@ ...@@ -9,15 +9,15 @@
"parents": { "parents": {
"/*": [ "/*": [
{ {
"xml": "<feature name=\"Toast\"><param name=\"ios-package\" value=\"Toast\" /></feature>", "xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>",
"count": 1 "count": 1
}, },
{ {
"xml": "<feature name=\"Device\"><param name=\"ios-package\" value=\"CDVDevice\" /></feature>", "xml": "<feature name=\"LocalNotification\"><param name=\"ios-package\" onload=\"true\" value=\"APPLocalNotification\" /><param name=\"onload\" value=\"true\" /></feature>",
"count": 1 "count": 1
}, },
{ {
"xml": "<feature name=\"LocalNotification\"><param name=\"ios-package\" onload=\"true\" value=\"APPLocalNotification\" /><param name=\"onload\" value=\"true\" /></feature>", "xml": "<feature name=\"Toast\"><param name=\"ios-package\" value=\"Toast\" /></feature>",
"count": 1 "count": 1
} }
] ]
...@@ -36,16 +36,16 @@ ...@@ -36,16 +36,16 @@
} }
}, },
"installed_plugins": { "installed_plugins": {
"nl.x-services.plugins.toast": {
"PACKAGE_NAME": "de.appplant.cordova.plugin.local-notification.example"
},
"de.appplant.cordova.plugin.local-notification": { "de.appplant.cordova.plugin.local-notification": {
"PACKAGE_NAME": "de.appplant.cordova.plugin.local-notification.example" "PACKAGE_NAME": "de.appplant.localnotification.example"
},
"nl.x-services.plugins.toast": {
"PACKAGE_NAME": "de.appplant.localnotification.example"
} }
}, },
"dependent_plugins": { "dependent_plugins": {
"org.apache.cordova.device": { "org.apache.cordova.device": {
"PACKAGE_NAME": "de.appplant.cordova.plugin.local-notification.example" "PACKAGE_NAME": "de.appplant.localnotification.example"
} }
} }
} }
\ No newline at end of file
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
"files": {} "files": {}
}, },
"installed_plugins": { "installed_plugins": {
"de.appplant.cordova.plugin.local-notification": { "nl.x-services.plugins.toast": {
"PACKAGE_NAME": "NotificationExample" "PACKAGE_NAME": "NotificationExample"
}, },
"nl.x-services.plugins.toast": { "de.appplant.cordova.plugin.local-notification": {
"PACKAGE_NAME": "NotificationExample" "PACKAGE_NAME": "NotificationExample"
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment