Commit 13af9eab by Sebastián Katzer

Update project and plugin

parent c4a5a7cb
......@@ -5,7 +5,7 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>AFAFE068-92EA-475E-8783-6E5FC17A7188</string>
<string>A63F5FF5-C059-403D-81B9-E740110FFC25</string>
<key>IDESourceControlProjectName</key>
<string>NotificationExample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
......
......@@ -29,6 +29,8 @@
#import <Cordova/CDVViewController.h>
extern NSString* const UIApplicationRegisterUserNotificationSettings;
@interface AppDelegate : NSObject <UIApplicationDelegate>{}
// invoke string is passed to your app on launch, this is only valid if you
......
......@@ -30,6 +30,8 @@
#import <Cordova/CDVPlugin.h>
NSString* const UIApplicationRegisterUserNotificationSettings = @"UIApplicationRegisterUserNotificationSettings";
@implementation AppDelegate
@synthesize window, viewController;
......@@ -148,4 +150,18 @@
[[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
......@@ -49,7 +49,7 @@
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>de.appplant.cordova.plugin.local-notification.example</string>
<string>de.appplant.localnotification.example</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
......
......@@ -21,9 +21,9 @@
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate.h"
#import "APPLocalNotification.h"
#import "APPLocalNotificationOptions.h"
#import "AppDelegate+APPLocalNotification.h"
#import "UIApplication+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 @@
UIUserNotificationType types;
UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [[UIApplication sharedApplication]
currentUserNotificationSettings];
types = settings.types|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil];
......
<?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="BackupWebStorage" value="cloud" />
<preference name="DisallowOverscroll" value="false" />
......@@ -23,9 +23,6 @@
</author>
<content src="index.html" />
<access origin="*" />
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
<feature name="Device">
<param name="ios-package" value="CDVDevice" />
</feature>
......@@ -33,4 +30,7 @@
<param name="ios-package" onload="true" value="APPLocalNotification" />
<param name="onload" value="true" />
</feature>
<feature name="Toast">
<param name="ios-package" value="Toast" />
</feature>
</widget>
cordova.define('cordova/plugin_list', function(require, exports, module) {
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",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [
......@@ -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",
"id": "org.apache.cordova.device.device",
"clobbers": [
......@@ -46,8 +46,8 @@ module.exports = [
module.exports.metadata =
// TOP OF METADATA
{
"nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3",
"org.apache.cordova.device": "0.3.0"
}
// BOTTOM OF METADATA
......
......@@ -2,5 +2,6 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ReferenceCachePath>C:\Users\sebastian\AppData\Local\Temp\yxmokjnx_CordovaApp.Phone_refcache</ReferenceCachePath>
<AutoRefresh>true</AutoRefresh>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -41,7 +41,7 @@
</Resources>
<Applications>
<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:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
......
......@@ -34,7 +34,7 @@
</Resources>
<Applications>
<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:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
......
cordova.define('cordova/plugin_list', function(require, exports, module) {
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",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [
......@@ -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",
"id": "org.apache.cordova.device.device",
"clobbers": [
......@@ -74,8 +74,8 @@ module.exports = [
module.exports.metadata =
// TOP OF METADATA
{
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"nl.x-services.plugins.toast": "2.0.3",
"de.appplant.cordova.plugin.local-notification": "0.8.2dev",
"org.apache.cordova.device": "0.3.0"
}
// BOTTOM OF METADATA
......
......@@ -32,14 +32,12 @@ exports.core = {
*/
deviceready: function () {
var plugin = cordova.plugins.notification.local,
args;
events = this.eventQueue;
this.isReady = true;
for (var i = 0; i < this.eventQueue.length; i++) {
args = this.eventQueue[i];
plugin.fireEvent.apply(plugin, args);
for (var i = 0; i < events.length; i++) {
plugin.fireEvent.apply(plugin, events[i]);
}
this.eventQueue = [];
......@@ -64,10 +62,8 @@ exports.core = {
notification = this.build(options);
this.cancelLocalNotification(options.id);
this.scheduleLocalNotification(notification, options);
this.scheduleBackupNotification(notification, options);
this.fireEvent('schedule', options);
this.callOnTrigger(options, triggerFn);
}
......@@ -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.
*
* @param {Object[]} notifications
......@@ -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.
*
* @param {int[]} ids
......@@ -182,9 +183,10 @@ exports.core = {
*/
clear: function (ids) {
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);
}
},
......@@ -196,8 +198,13 @@ exports.core = {
* Local notification ID
*/
clearLocalNotification: function (id) {
var notification = this.getAll([id])[0];
this.getToastHistory().remove('Toast' + id);
if (this.isRepeating(notification))
return;
if (this.isTriggered(id) && !this.isScheduled(id)) {
this.cancelLocalNotification(id);
}
......@@ -225,7 +232,8 @@ exports.core = {
*/
cancel: function (ids) {
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.fireEvent('cancel', notification);
......@@ -275,7 +283,7 @@ exports.core = {
* Local notification ID
*/
isPresent: function (id) {
return this.getAllIds().indexOf(id) > -1;
return !!this.findToastById(id);
},
/**
......@@ -285,7 +293,9 @@ exports.core = {
* Local notification 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 = {
* Local notification 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 = {
var toasts = this.getScheduledToasts(),
notifications = [];
if (ids.length === 0) {
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
......@@ -392,7 +404,7 @@ exports.core = {
* List of local notification IDs
*/
getScheduled: function (ids) {
if (ids.length === 0) {
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
......@@ -407,7 +419,7 @@ exports.core = {
* List of local notification IDs
*/
getTriggered: function (ids) {
if (ids.length === 0) {
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
......
......@@ -19,6 +19,9 @@ cordova.define("de.appplant.cordova.plugin.local-notification.LocalNotification.
under the License.
*/
var channel = require('cordova/channel');
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core;
......@@ -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.
*
* @param {String} path
......@@ -87,7 +102,7 @@ exports.parseSound = function (path) {
return audio;
};
/**
/**
* Builds the xml payload for a local notification based on its options.
*
* @param {Object} options
......@@ -117,7 +132,7 @@ exports.build = function (options) {
return notification;
};
/**
/**
* Builds the toast template with the right style depend on the options.
*
* @param {Object} options
......@@ -240,6 +255,9 @@ exports.isToastTriggered = function (toast) {
notification = this.getAll(id)[0];
fireDate = new Date((notification.at) * 1000);
if (this.isRepeating(notification))
return false;
return fireDate <= new Date();
};
......@@ -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.
*
* @return String
......@@ -328,6 +360,31 @@ exports.fireEvent = function (event, notification) {
* 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
document.addEventListener('pause', function () {
exports.isInBackground = true;
......@@ -343,16 +400,4 @@ document.addEventListener('deviceready', function () {
exports.isInBackground = 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 @@
<!-- info -->
<info>
Your support is needed. If you use the 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
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#supporting
Thank you!
</info>
......@@ -59,9 +59,6 @@
</feature>
</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" />
<source-file src="src/ios/APPLocalNotification.m" />
......@@ -74,6 +71,14 @@
<header-file src="src/ios/UILocalNotification+APPLocalNotification.h" />
<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>
<!-- 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 @@
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "AppDelegate.h"
#import "APPLocalNotification.h"
#import "APPLocalNotificationOptions.h"
#import "AppDelegate+APPLocalNotification.h"
#import "UIApplication+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 @@
UIUserNotificationType types;
UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [[UIApplication sharedApplication]
currentUserNotificationSettings];
types = settings.types|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil];
......
......@@ -32,14 +32,12 @@ exports.core = {
*/
deviceready: function () {
var plugin = cordova.plugins.notification.local,
args;
events = this.eventQueue;
this.isReady = true;
for (var i = 0; i < this.eventQueue.length; i++) {
args = this.eventQueue[i];
plugin.fireEvent.apply(plugin, args);
for (var i = 0; i < events.length; i++) {
plugin.fireEvent.apply(plugin, events[i]);
}
this.eventQueue = [];
......@@ -54,8 +52,8 @@ exports.core = {
* 'schedule' or 'update'
*/
schedule: function (notifications) {
var triggerFn = function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
};
......@@ -64,10 +62,8 @@ exports.core = {
notification = this.build(options);
this.cancelLocalNotification(options.id);
this.scheduleLocalNotification(notification, options);
this.scheduleBackupNotification(notification, options);
this.fireEvent('schedule', options);
this.callOnTrigger(options, triggerFn);
}
......@@ -128,15 +124,22 @@ exports.core = {
},
/**
* Updates a single local notification.
* Updates the badge number of the active tile.
*
* @param {Object} notification
* The local notification
* @param {Object} updates
* Updated properties
* @param {Number} badge
* The badge number. Zero will clean the badge.
*/
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 = {
},
/**
* 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.
*
* @param {int[]} ids
......@@ -163,9 +183,10 @@ exports.core = {
*/
clear: function (ids) {
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);
}
},
......@@ -177,8 +198,13 @@ exports.core = {
* Local notification ID
*/
clearLocalNotification: function (id) {
var notification = this.getAll([id])[0];
this.getToastHistory().remove('Toast' + id);
if (this.isRepeating(notification))
return;
if (this.isTriggered(id) && !this.isScheduled(id)) {
this.cancelLocalNotification(id);
}
......@@ -206,7 +232,8 @@ exports.core = {
*/
cancel: function (ids) {
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.fireEvent('cancel', notification);
......@@ -256,7 +283,7 @@ exports.core = {
* Local notification ID
*/
isPresent: function (id) {
return this.getAllIds().indexOf(id) > -1;
return !!this.findToastById(id);
},
/**
......@@ -266,7 +293,9 @@ exports.core = {
* Local notification 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 = {
* Local notification 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 = {
var toasts = this.getScheduledToasts(),
notifications = [];
if (ids.length === 0) {
ids = getAllIds();
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
for (var index = 0; index < ids.length; index++) {
......@@ -373,7 +404,7 @@ exports.core = {
* List of local notification IDs
*/
getScheduled: function (ids) {
if (ids.length === 0) {
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
......@@ -388,7 +419,7 @@ exports.core = {
* List of local notification IDs
*/
getTriggered: function (ids) {
if (ids.length === 0) {
if (!ids || ids.length === 0) {
ids = this.getAllIds();
}
......
......@@ -19,6 +19,9 @@
under the License.
*/
var channel = require('cordova/channel');
exports = require('de.appplant.cordova.plugin.local-notification.LocalNotification.Proxy.Core').core;
......@@ -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.
*
* @param {String} path
......@@ -93,38 +108,14 @@ exports.parseSound = function (path) {
* @param {Object} options
* Local notification properties
*
* @return {String}
* Windows.Data.Xml.Dom.XmlDocument
* @return Windows.Data.Xml.Dom.XmlDocument
*/
exports.build = function (options) {
var title = options.title,
message = options.text || '',
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();
var template = this.buildToastTemplate(options),
notification = new Windows.Data.Xml.Dom.XmlDocument();
try {
notification.loadXml(payload);
notification.loadXml(template);
} catch (e) {
console.error(
'LocalNotification#schedule',
......@@ -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.
*/
exports.getToastHistory = function () {
......@@ -222,6 +255,9 @@ exports.isToastTriggered = function (toast) {
notification = this.getAll(id)[0];
fireDate = new Date((notification.at) * 1000);
if (this.isRepeating(notification))
return false;
return fireDate <= new Date();
};
......@@ -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.
*
* @return String
......@@ -310,6 +360,31 @@ exports.fireEvent = function (event, notification) {
* 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
document.addEventListener('pause', function () {
exports.isInBackground = true;
......@@ -324,15 +399,3 @@ document.addEventListener('resume', function () {
document.addEventListener('deviceready', function () {
exports.isInBackground = 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 @@
"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
},
{
"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
},
{
"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
}
]
......@@ -36,16 +36,16 @@
}
},
"installed_plugins": {
"nl.x-services.plugins.toast": {
"PACKAGE_NAME": "de.appplant.cordova.plugin.local-notification.example"
},
"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": {
"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 @@
"files": {}
},
"installed_plugins": {
"de.appplant.cordova.plugin.local-notification": {
"nl.x-services.plugins.toast": {
"PACKAGE_NAME": "NotificationExample"
},
"nl.x-services.plugins.toast": {
"de.appplant.cordova.plugin.local-notification": {
"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