From 35b00f3c7977a5e130e4b963c9c4739f6877c973 Mon Sep 17 00:00:00 2001 From: Marcelo Rebasti Date: Sun, 4 Oct 2015 01:07:41 -0300 Subject: [PATCH 01/51] Changing android-support dependency declaration to be compatible with other plugins like phonegap-plugin-push and cordova-plugin-facebook4. Issue katzer/cordova-plugin-local-notifications#632 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 169260784..7efd34343 100644 --- a/plugin.xml +++ b/plugin.xml @@ -79,7 +79,7 @@ - + From 829501a9a65447e961bd255ce9cbfb55c71c640d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 9 Oct 2015 16:35:24 +0700 Subject: [PATCH 02/51] Fix compiler warning --- src/ios/APPLocalNotificationOptions.m | 2 +- src/ios/UILocalNotification+APPLocalNotification.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/APPLocalNotificationOptions.m b/src/ios/APPLocalNotificationOptions.m index ce931ce7e..ac90f9932 100644 --- a/src/ios/APPLocalNotificationOptions.m +++ b/src/ios/APPLocalNotificationOptions.m @@ -46,7 +46,7 @@ @implementation APPLocalNotificationOptions */ - (id) initWithDict:(NSDictionary*)dictionary { - self = [super init]; + self = [self init]; self.dict = dictionary; diff --git a/src/ios/UILocalNotification+APPLocalNotification.m b/src/ios/UILocalNotification+APPLocalNotification.m index 80012f89f..d225cf526 100644 --- a/src/ios/UILocalNotification+APPLocalNotification.m +++ b/src/ios/UILocalNotification+APPLocalNotification.m @@ -41,7 +41,7 @@ @implementation UILocalNotification (APPLocalNotification) */ - (id) initWithOptions:(NSDictionary*)dict { - self = [super init]; + self = [self init]; [self setUserInfo:dict]; [self __init]; From d74caf68018c11db42f9720ceb14ff850f293d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 8 Nov 2015 14:38:10 +0100 Subject: [PATCH 03/51] Fix getIds returns none existing notifications --- src/android/ClickActivity.java | 10 +++++----- src/android/notification/ClickActivity.java | 6 ++++++ src/android/notification/Notification.java | 18 +++++------------- src/android/notification/Options.java | 8 ++++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/android/ClickActivity.java b/src/android/ClickActivity.java index d366d3555..85a5355e5 100644 --- a/src/android/ClickActivity.java +++ b/src/android/ClickActivity.java @@ -44,13 +44,13 @@ public class ClickActivity extends de.appplant.cordova.plugin.notification.Click public void onClick(Notification notification) { LocalNotification.fireEvent("click", notification); - if (!notification.getOptions().isOngoing()) { - String event = notification.isRepeating() ? "clear" : "cancel"; + super.onClick(notification); - LocalNotification.fireEvent(event, notification); - } + if (notification.getOptions().isOngoing()) + return; - super.onClick(notification); + String event = notification.isRepeating() ? "clear" : "cancel"; + LocalNotification.fireEvent(event, notification); } /** diff --git a/src/android/notification/ClickActivity.java b/src/android/notification/ClickActivity.java index 01af5c457..dcc0390dc 100644 --- a/src/android/notification/ClickActivity.java +++ b/src/android/notification/ClickActivity.java @@ -40,6 +40,12 @@ public class ClickActivity extends AbstractClickActivity { @Override public void onClick(Notification notification) { launchApp(); + + if (notification.isRepeating()) { + notification.clear(); + } else { + notification.cancel(); + } } /** diff --git a/src/android/notification/Notification.java b/src/android/notification/Notification.java index 5dba9d54f..c78d25d4d 100644 --- a/src/android/notification/Notification.java +++ b/src/android/notification/Notification.java @@ -144,8 +144,7 @@ protected boolean isUpdate () { if (!options.getDict().has("updatedAt")) return false; - long now = new Date().getTime(); - + long now = new Date().getTime(); long updatedAt = options.getDict().optLong("updatedAt", now); return (now - updatedAt) < 1000; @@ -184,14 +183,14 @@ public void schedule() { /** * Clear the local notification without canceling repeating alarms. - * */ public void clear () { - if (!isRepeating() && wasInThePast()) { + + if (!isRepeating() && wasInThePast()) unpersist(); - } else { + + if (!isRepeating()) getNotMgr().cancel(getId()); - } } /** @@ -239,13 +238,6 @@ private void showNotification () { } } - /** - * Show as modal dialog when in foreground. - */ - private void showDialog () { - // TODO - } - /** * Count of triggers since schedule. */ diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 198a52f41..8b76196e6 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -213,10 +213,10 @@ public Date getTriggerDate() { * Trigger date in milliseconds. */ public long getTriggerTime() { - return Math.max( - System.currentTimeMillis(), - options.optLong("at", 0) * 1000 - ); + //return Math.max( + // System.currentTimeMillis(), + return options.optLong("at", 0) * 1000; + //); } /** From 9b54ec61dbb6cfc3de22dae42322f0f81e065b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 8 Nov 2015 16:02:40 +0100 Subject: [PATCH 04/51] Release version 0.8.2 --- CHANGELOG.md | 12 ++++++++++ package.json | 35 ++++++++++++++++++++++++++++++ plugin.xml | 3 +-- src/android/LocalNotification.java | 1 - 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 611e02f8b..edc3ad945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. +#### Version 0.8.2 (08.11.2015) +- Submitted to npm +- Initial support for the `windows` platform +- Re-add autoCancel option on Android +- Warn about unknown properties +- Fix crash on iOS 9 +- Fixed webView-Problems with cordova-android 4.0 +- Fix get* with single id +- Fix issue when passing data in milliseconds +- Update device plugin id +- Several other fixes + #### Version 0.8.1 (08.03.2015) - Fix incompatibility with cordova version 3.5-3.0 diff --git a/package.json b/package.json new file mode 100644 index 000000000..19ccf1e41 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "version": "0.8.2", + "name": "de.appplant.cordova.plugin.local-notification", + "cordova_name": "Cordova LocalNotification Plugin", + "description": "Cordova plugin to schedule and query local notifications", + "author": "Sebastián Katzer", + "license": "Apache 2.0", + "repo": "https://github.com/katzer/cordova-plugin-local-notifications.git", + "issue": "https://github.com/katzer/cordova-plugin-local-notifications/issues", + "keywords": [ + "appplant", + "notification", + "local notification", + "cordova", + "ecosystem:cordova", + "cordova-android", + "cordova-ios", + "cordova-windows" + ], + "platforms": [ + "ios", + "android", + "windows" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.6.0" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/katzer/cordova-plugin-local-notifications.git" + } +} diff --git a/plugin.xml b/plugin.xml index 7efd34343..e8c8fe18c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.8.2"> LocalNotification @@ -20,7 +20,6 @@ - diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 906c8d69e..55926213f 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -24,7 +24,6 @@ package de.appplant.cordova.plugin.localnotification; import android.app.Activity; -import android.os.Build; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; From 50ab0d05f3e2267796a765aa021cde8bf15a4fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 8 Nov 2015 16:13:56 +0100 Subject: [PATCH 05/51] Added npm badge button --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 878632ba0..6aea8cb1f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ +[![npm version](https://badge.fury.io/js/de.appplant.cordova.plugin.local-notification.svg)](http://badge.fury.io/js/de.appplant.cordova.plugin.local-notification) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=L3HKQCD9UA35A "Donate once-off to this project using Paypal") #### :bangbang: Please vote for these cordova-windows issues :bangbang: From 53886ccea9da5f84d95d65e5a78ae8aefafc03bb Mon Sep 17 00:00:00 2001 From: Rich Sage Date: Thu, 26 Nov 2015 09:32:47 +0000 Subject: [PATCH 06/51] Catch previously-valid notification non-int keys. --- src/android/notification/Manager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/android/notification/Manager.java b/src/android/notification/Manager.java index 03ea384f9..d5bd49376 100644 --- a/src/android/notification/Manager.java +++ b/src/android/notification/Manager.java @@ -30,6 +30,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.lang.NumberFormatException; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; @@ -193,7 +194,11 @@ public List getIds() { ArrayList ids = new ArrayList(); for (String key : keys) { - ids.add(Integer.parseInt(key)); + try { + ids.add(Integer.parseInt(key)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } } return ids; From 248f30d3ecb4d9ff09746b0c9be4cb15ed42dfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 3 Dec 2015 17:22:21 +0100 Subject: [PATCH 07/51] Bump version to next dev cycle 0.8.3-dev --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index e8c8fe18c..049d9290e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.8.3-dev"> LocalNotification From 2d4033c32d425bee139f6badbd273c88c53585e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 3 Dec 2015 17:25:31 +0100 Subject: [PATCH 08/51] Fixed crashing `get` if notification doesn't exist --- CHANGELOG.md | 3 +++ src/ios/APPLocalNotification.m | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edc3ad945..920aa9743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. +#### Version 0.8.3 (not yet released) +- Fixed crashing `get(ID)` if notification doesn't exist + #### Version 0.8.2 (08.11.2015) - Submitted to npm - Initial support for the `windows` platform diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 43cf9f8cb..819af1e89 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -393,7 +393,7 @@ - (void) getOption:(CDVInvokedUrlCommand*)command } result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK - messageAsDictionary:notifications[0]]; + messageAsDictionary:[notifications firstObject]]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; From a65f48c50116b34fbf82827831debc11989f933f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 8 Dec 2015 11:34:51 +0100 Subject: [PATCH 09/51] Fixes #710 crash due to >500 notifications --- CHANGELOG.md | 1 + src/android/notification/Builder.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 920aa9743..773025be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. #### Version 0.8.3 (not yet released) +- Fixed #710 crash due to >500 notifications (Android) - Fixed crashing `get(ID)` if notification doesn't exist #### Version 0.8.2 (08.11.2015) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index a0be8b939..109f11622 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -162,7 +162,7 @@ private void applyDeleteReceiver(NotificationCompat.Builder builder) { .putExtra(Options.EXTRA, options.toString()); PendingIntent dpi = PendingIntent.getBroadcast( - context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); + context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setDeleteIntent(dpi); } @@ -186,7 +186,7 @@ private void applyContentReceiver(NotificationCompat.Builder builder) { int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity( - context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT); + context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); } From fd647138129154670cebff8d12b9b4f88abd2098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 8 Dec 2015 15:08:07 +0100 Subject: [PATCH 10/51] Closes #727 - quarter intervall for iOS and Android --- CHANGELOG.md | 1 + src/android/notification/Options.java | 3 +++ src/ios/APPLocalNotificationOptions.m | 3 +++ 3 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 773025be6..618428bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. #### Version 0.8.3 (not yet released) +- New "quarter" intervall for iOS & Android - Fixed #710 crash due to >500 notifications (Android) - Fixed crashing `get(ID)` if notification doesn't exist diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 8b76196e6..ca9e8f8db 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -109,6 +109,9 @@ private void parseInterval() { if (every.equals("month")) { interval = AlarmManager.INTERVAL_DAY * 31; } else + if (every.equals("quarter")) { + interval = AlarmManager.INTERVAL_HOUR * 2190; + } else if (every.equals("year")) { interval = AlarmManager.INTERVAL_DAY * 365; } else { diff --git a/src/ios/APPLocalNotificationOptions.m b/src/ios/APPLocalNotificationOptions.m index ac90f9932..6918919b4 100644 --- a/src/ios/APPLocalNotificationOptions.m +++ b/src/ios/APPLocalNotificationOptions.m @@ -173,6 +173,9 @@ - (NSCalendarUnit) repeatInterval else if ([interval isEqualToString:@"month"]) { return NSCalendarUnitMonth; } + else if ([interval isEqualToString:@"quarter"]) { + return NSCalendarUnitQuarter; + } else if ([interval isEqualToString:@"year"]) { return NSCalendarUnitYear; } From 3a2ed5dc3cca56cf8d7754eb84d044a1b9710922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 8 Dec 2015 17:10:09 +0100 Subject: [PATCH 11/51] Fixes #732 loop between update and trigger --- CHANGELOG.md | 1 + .../notification/AbstractTriggerReceiver.java | 2 +- src/android/notification/Manager.java | 3 +-- src/android/notification/Notification.java | 18 ++++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 618428bc4..340c9d170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Version 0.8.3 (not yet released) - New "quarter" intervall for iOS & Android +- Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) - Fixed crashing `get(ID)` if notification doesn't exist diff --git a/src/android/notification/AbstractTriggerReceiver.java b/src/android/notification/AbstractTriggerReceiver.java index fc6759c52..459e6d83a 100644 --- a/src/android/notification/AbstractTriggerReceiver.java +++ b/src/android/notification/AbstractTriggerReceiver.java @@ -70,7 +70,7 @@ public void onReceive(Context context, Intent intent) { Builder builder = new Builder(options); Notification notification = buildNotification(builder); - boolean updated = notification.isUpdate(); + boolean updated = notification.isUpdate(false); onTrigger(notification, updated); } diff --git a/src/android/notification/Manager.java b/src/android/notification/Manager.java index 03ea384f9..8fbe27475 100644 --- a/src/android/notification/Manager.java +++ b/src/android/notification/Manager.java @@ -31,7 +31,6 @@ import org.json.JSONObject; import java.util.ArrayList; -import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -121,7 +120,7 @@ public Notification update (int id, JSONObject updates, Class receiver) { notification.getOptions().getDict(), updates); try { - options.putOpt("updatedAt", new Date().getTime()); + options.putOpt("updated", true); } catch (JSONException ignore) {} return schedule(options, receiver); diff --git a/src/android/notification/Notification.java b/src/android/notification/Notification.java index c78d25d4d..d9aaf7271 100644 --- a/src/android/notification/Notification.java +++ b/src/android/notification/Notification.java @@ -138,16 +138,18 @@ public boolean isTriggered () { /** * If the notification is an update. + * + * @param keepFlag + * Set to false to remove the flag from the option map */ - protected boolean isUpdate () { - - if (!options.getDict().has("updatedAt")) - return false; + protected boolean isUpdate (boolean keepFlag) { + boolean updated = options.getDict().optBoolean("updated", false); - long now = new Date().getTime(); - long updatedAt = options.getDict().optLong("updatedAt", now); + if (!keepFlag) { + options.getDict().remove("updated"); + } - return (now - updatedAt) < 1000; + return updated; } /** @@ -268,7 +270,7 @@ public String toString() { } json.remove("firstAt"); - json.remove("updatedAt"); + json.remove("updated"); json.remove("soundUri"); json.remove("iconUri"); From d2bd748fff52f58046eccf0c954ec788be86e5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 8 Dec 2015 18:19:46 +0100 Subject: [PATCH 12/51] Fixed crashing `get` if notification doesn't exist --- src/android/LocalNotification.java | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 55926213f..115ae7b95 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -36,6 +36,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import de.appplant.cordova.plugin.notification.Manager; @@ -234,6 +235,9 @@ private void update (JSONArray updates) { Notification notification = getNotificationMgr().update(id, update, TriggerReceiver.class); + if (notification == null) + continue; + fireEvent("update", notification); } } @@ -251,9 +255,10 @@ private void cancel (JSONArray ids) { Notification notification = getNotificationMgr().cancel(id); - if (notification != null) { - fireEvent("cancel", notification); - } + if (notification == null) + continue; + + fireEvent("cancel", notification); } } @@ -278,9 +283,10 @@ private void clear(JSONArray ids){ Notification notification = getNotificationMgr().clear(id); - if (notification != null) { - fireEvent("clear", notification); - } + if (notification == null) + continue; + + fireEvent("clear", notification); } } @@ -469,11 +475,20 @@ private void getOptions (String id, Notification.Type type, CallbackContext command) { JSONArray ids = new JSONArray().put(id); + PluginResult result; - JSONObject options = - getNotificationMgr().getOptionsBy(type, toList(ids)).get(0); + List options = + getNotificationMgr().getOptionsBy(type, toList(ids)); - command.success(options); + if (options.isEmpty()) { + // Status.NO_RESULT led to no callback invocation :( + // Status.OK led to no NPE and crash + result = new PluginResult(PluginResult.Status.NO_RESULT); + } else { + result = new PluginResult(PluginResult.Status.OK, options.get(0)); + } + + command.sendPluginResult(result); } /** From 30ac53ec871ebaef95fa4b9073966966e498a3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 8 Dec 2015 23:27:10 +0100 Subject: [PATCH 13/51] Added version constraint for plugman --- plugin.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 049d9290e..3c2523787 100644 --- a/plugin.xml +++ b/plugin.xml @@ -20,6 +20,7 @@ + @@ -78,7 +79,7 @@ - + From 38f58ac22734f1e7e8ed803081842e79c79028c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Wed, 9 Dec 2015 10:44:52 +0100 Subject: [PATCH 14/51] Fixes #682 crash while resuming app from notification --- CHANGELOG.md | 1 + src/android/notification/AbstractClickActivity.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 340c9d170..6daed5a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - New "quarter" intervall for iOS & Android - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) +- Fixed #682 crash while resuming app from notification (Android 6) - Fixed crashing `get(ID)` if notification doesn't exist #### Version 0.8.2 (08.11.2015) diff --git a/src/android/notification/AbstractClickActivity.java b/src/android/notification/AbstractClickActivity.java index a02a9981e..5b70e1480 100644 --- a/src/android/notification/AbstractClickActivity.java +++ b/src/android/notification/AbstractClickActivity.java @@ -67,6 +67,16 @@ public void onCreate (Bundle state) { } } + /** + * Fixes "Unable to resume activity" error. + * Theme_NoDisplay: Activities finish themselves before being resumed. + */ + @Override + protected void onResume() { + super.onResume(); + finish(); + } + /** * Called when local notification was clicked by the user. * From 9ac02bdcfc63fdf3f8f8f163bf6f6dd93db5ce59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Wed, 9 Dec 2015 17:04:42 +0100 Subject: [PATCH 15/51] Fixes #731 Prevent crash when user info is nil --- src/ios/APPLocalNotification.m | 2 +- src/ios/UILocalNotification+APPLocalNotification.m | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 819af1e89..9772e5ef3 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -571,7 +571,7 @@ - (void) didReceiveLocalNotification:(NSNotification*)localNotification { UILocalNotification* notification = [localNotification object]; - if ([notification wasUpdated]) + if ([notification userInfo] == NULL || [notification wasUpdated] ) return; NSTimeInterval timeInterval = [notification timeIntervalSinceLastTrigger]; diff --git a/src/ios/UILocalNotification+APPLocalNotification.m b/src/ios/UILocalNotification+APPLocalNotification.m index d225cf526..383725389 100644 --- a/src/ios/UILocalNotification+APPLocalNotification.m +++ b/src/ios/UILocalNotification+APPLocalNotification.m @@ -168,9 +168,12 @@ - (NSString*) encodeToJSON [obj removeObjectForKey:@"updatedAt"]; + if (obj == NULL || obj.count == 0) + return json; + data = [NSJSONSerialization dataWithJSONObject:obj options:NSJSONWritingPrettyPrinted - error:Nil]; + error:NULL]; json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; From 1eaaacda4433b8ce3d4c061a9986a745e61fe495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Wed, 9 Dec 2015 17:08:15 +0100 Subject: [PATCH 16/51] Updated dependency id and engine constraint --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 3c2523787..a08dbc5a9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,10 +21,12 @@ + + @@ -53,8 +55,6 @@ - - From 52054f5d0cdef57c93cc489bcb59f7b8272340f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 10 Dec 2015 15:37:41 +0100 Subject: [PATCH 17/51] Optimized imports --- src/android/LocalNotification.java | 1 - src/android/notification/Builder.java | 12 ++++++------ src/android/notification/Manager.java | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 115ae7b95..b4be09fe9 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -36,7 +36,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import de.appplant.cordova.plugin.notification.Manager; diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index 109f11622..5397b0c61 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -157,14 +157,14 @@ private void applyDeleteReceiver(NotificationCompat.Builder builder) { if (clearReceiver == null) return; - Intent deleteIntent = new Intent(context, clearReceiver) + Intent intent = new Intent(context, clearReceiver) .setAction(options.getIdStr()) .putExtra(Options.EXTRA, options.toString()); - PendingIntent dpi = PendingIntent.getBroadcast( - context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent deleteIntent = PendingIntent.getBroadcast( + context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setDeleteIntent(dpi); + builder.setDeleteIntent(deleteIntent); } /** @@ -183,10 +183,10 @@ private void applyContentReceiver(NotificationCompat.Builder builder) { .putExtra(Options.EXTRA, options.toString()) .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); - int requestCode = new Random().nextInt(); + int reqCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity( - context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); + context, reqCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); } diff --git a/src/android/notification/Manager.java b/src/android/notification/Manager.java index c6e819ddf..3505c9316 100644 --- a/src/android/notification/Manager.java +++ b/src/android/notification/Manager.java @@ -30,7 +30,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.lang.NumberFormatException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; From 4f4147d0381b1c75d655b979a18d9f7999f3f09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 10 Dec 2015 19:53:25 +0100 Subject: [PATCH 18/51] Fixes #588 crash when basename & extension can't be extracted --- CHANGELOG.md | 1 + src/android/notification/AssetUtil.java | 367 ++++++++++++------------ 2 files changed, 183 insertions(+), 185 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6daed5a59..c901b9466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Version 0.8.3 (not yet released) - New "quarter" intervall for iOS & Android +- Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) - Fixed #682 crash while resuming app from notification (Android 6) diff --git a/src/android/notification/AssetUtil.java b/src/android/notification/AssetUtil.java index 2da8a2c3b..eff93647b 100644 --- a/src/android/notification/AssetUtil.java +++ b/src/android/notification/AssetUtil.java @@ -42,6 +42,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.UUID; /** * Util class to map unified asset URIs to native URIs. URIs like file:/// @@ -61,15 +62,15 @@ class AssetUtil { // resources and app directory. private final Context context; - /** - * Constructor - * - * @param context + /** + * Constructor + * + * @param context * Application context - */ - private AssetUtil(Context context) { - this.context = context; - } + */ + private AssetUtil(Context context) { + this.context = context; + } /** * Static method to retrieve class instance. @@ -100,223 +101,199 @@ Uri parseSound (String path) { return parse(path); } - /** - * The URI for a path. - * - * @param path + /** + * The URI for a path. + * + * @param path * The given path - */ + */ Uri parse (String path) { - if (path.startsWith("res:")) { - return getUriForResourcePath(path); - } else if (path.startsWith("file:///")) { - return getUriFromPath(path); - } else if (path.startsWith("file://")) { - return getUriFromAsset(path); - } else if (path.startsWith("http")){ - return getUriFromRemote(path); - } - - return Uri.EMPTY; - } - - /** - * URI for a file. - * - * @param path - * Absolute path like file:///... - * - * @return - * URI pointing to the given path - */ - private Uri getUriFromPath(String path) { - String absPath = path.replaceFirst("file://", ""); - File file = new File(absPath); - - if (!file.exists()) { - Log.e("Asset", "File not found: " + file.getAbsolutePath()); - return Uri.EMPTY; - } - - return Uri.fromFile(file); - } - - /** - * URI for an asset. - * - * @param path - * Asset path like file://... - * - * @return + if (path.startsWith("res:")) { + return getUriForResourcePath(path); + } else if (path.startsWith("file:///")) { + return getUriFromPath(path); + } else if (path.startsWith("file://")) { + return getUriFromAsset(path); + } else if (path.startsWith("http")){ + return getUriFromRemote(path); + } + + return Uri.EMPTY; + } + + /** + * URI for a file. + * + * @param path + * Absolute path like file:///... + * + * @return * URI pointing to the given path - */ - private Uri getUriFromAsset(String path) { - File dir = context.getExternalCacheDir(); + */ + private Uri getUriFromPath(String path) { + String absPath = path.replaceFirst("file://", ""); + File file = new File(absPath); + + if (!file.exists()) { + Log.e("Asset", "File not found: " + file.getAbsolutePath()); + return Uri.EMPTY; + } - if (dir == null) { - Log.e("Asset", "Missing external cache dir"); - return Uri.EMPTY; - } + return Uri.fromFile(file); + } + /** + * URI for an asset. + * + * @param path + * Asset path like file://... + * + * @return + * URI pointing to the given path + */ + private Uri getUriFromAsset(String path) { String resPath = path.replaceFirst("file:/", "www"); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); - String storage = dir.toString() + STORAGE_FOLDER; - File file = new File(storage, fileName); + File file = getTmpFile(fileName); - //noinspection ResultOfMethodCallIgnored - new File(storage).mkdir(); + if (file == null) { + Log.e("Asset", "Missing external cache dir"); + return Uri.EMPTY; + } - try { - AssetManager assets = context.getAssets(); - FileOutputStream outStream = new FileOutputStream(file); - InputStream inputStream = assets.open(resPath); + try { + AssetManager assets = context.getAssets(); + FileOutputStream outStream = new FileOutputStream(file); + InputStream inputStream = assets.open(resPath); - copyFile(inputStream, outStream); + copyFile(inputStream, outStream); - outStream.flush(); - outStream.close(); + outStream.flush(); + outStream.close(); - return Uri.fromFile(file); + return Uri.fromFile(file); - } catch (Exception e) { - Log.e("Asset", "File not found: assets/" + resPath); - e.printStackTrace(); - } + } catch (Exception e) { + Log.e("Asset", "File not found: assets/" + resPath); + e.printStackTrace(); + } - return Uri.EMPTY; - } + return Uri.EMPTY; + } - /** - * The URI for a resource. - * - * @param path - * The given relative path - * - * @return + /** + * The URI for a resource. + * + * @param path + * The given relative path + * + * @return * URI pointing to the given path - */ - private Uri getUriForResourcePath(String path) { - File dir = context.getExternalCacheDir(); - - if (dir == null) { - Log.e("Asset", "Missing external cache dir"); - return Uri.EMPTY; - } - + */ + private Uri getUriForResourcePath(String path) { String resPath = path.replaceFirst("res://", ""); + int resId = getResIdForDrawable(resPath); + File file = getTmpFile(); - int resId = getResIdForDrawable(resPath); - - if (resId == 0) { - Log.e("Asset", "File not found: " + resPath); - return Uri.EMPTY; - } - - String resName = extractResourceName(resPath); - String extName = extractResourceExtension(resPath); - String storage = dir.toString() + STORAGE_FOLDER; - File file = new File(storage, resName + extName); + if (resId == 0) { + Log.e("Asset", "File not found: " + resPath); + return Uri.EMPTY; + } - //noinspection ResultOfMethodCallIgnored - new File(storage).mkdir(); + if (file == null) { + Log.e("Asset", "Missing external cache dir"); + return Uri.EMPTY; + } - try { - Resources res = context.getResources(); - FileOutputStream outStream = new FileOutputStream(file); - InputStream inputStream = res.openRawResource(resId); - copyFile(inputStream, outStream); + try { + Resources res = context.getResources(); + FileOutputStream outStream = new FileOutputStream(file); + InputStream inputStream = res.openRawResource(resId); + copyFile(inputStream, outStream); - outStream.flush(); - outStream.close(); + outStream.flush(); + outStream.close(); - return Uri.fromFile(file); + return Uri.fromFile(file); - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { + e.printStackTrace(); + } return Uri.EMPTY; - } + } - /** - * Uri from remote located content. + /** + * Uri from remote located content. * - * @param path + * @param path * Remote address * - * @return + * @return * Uri of the downloaded file - */ - private Uri getUriFromRemote(String path) { - File dir = context.getExternalCacheDir(); + */ + private Uri getUriFromRemote(String path) { + File file = getTmpFile(); - if (dir == null) { + if (file == null) { Log.e("Asset", "Missing external cache dir"); return Uri.EMPTY; } - String resName = extractResourceName(path); - String extName = extractResourceExtension(path); - String storage = dir.toString() + STORAGE_FOLDER; - File file = new File(storage, resName + extName); - - //noinspection ResultOfMethodCallIgnored - new File(storage).mkdir(); - try { URL url = new URL(path); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - StrictMode.ThreadPolicy policy = - new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.ThreadPolicy policy = + new StrictMode.ThreadPolicy.Builder().permitAll().build(); - StrictMode.setThreadPolicy(policy); + StrictMode.setThreadPolicy(policy); connection.setRequestProperty("Connection", "close"); connection.setConnectTimeout(5000); - connection.connect(); + connection.connect(); - InputStream input = connection.getInputStream(); - FileOutputStream outStream = new FileOutputStream(file); + InputStream input = connection.getInputStream(); + FileOutputStream outStream = new FileOutputStream(file); - copyFile(input, outStream); + copyFile(input, outStream); - outStream.flush(); - outStream.close(); + outStream.flush(); + outStream.close(); - return Uri.fromFile(file); + return Uri.fromFile(file); - } catch (MalformedURLException e) { - Log.e("Asset", "Incorrect URL"); - e.printStackTrace(); - } catch (FileNotFoundException e) { - Log.e("Asset", "Failed to create new File from HTTP Content"); - e.printStackTrace(); - } catch (IOException e) { - Log.e("Asset", "No Input can be created from http Stream"); - e.printStackTrace(); - } + } catch (MalformedURLException e) { + Log.e("Asset", "Incorrect URL"); + e.printStackTrace(); + } catch (FileNotFoundException e) { + Log.e("Asset", "Failed to create new File from HTTP Content"); + e.printStackTrace(); + } catch (IOException e) { + Log.e("Asset", "No Input can be created from http Stream"); + e.printStackTrace(); + } return Uri.EMPTY; - } - - /** - * Copy content from input stream into output stream. - * - * @param in - * The input stream - * @param out - * The output stream - */ - private void copyFile(InputStream in, OutputStream out) throws IOException { - byte[] buffer = new byte[1024]; - int read; - - while ((read = in.read(buffer)) != -1) { - out.write(buffer, 0, read); - } - } + } + + /** + * Copy content from input stream into output stream. + * + * @param in + * The input stream + * @param out + * The output stream + */ + private void copyFile(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + int read; + + while ((read = in.read(buffer)) != -1) { + out.write(buffer, 0, read); + } + } /** * Resource ID for drawable. @@ -343,7 +320,7 @@ int getResIdForDrawable(String resPath) { * Resource path as string */ int getResIdForDrawable(String clsName, String resPath) { - String drawable = extractResourceName(resPath); + String drawable = getBaseName(resPath); int resId = 0; try { @@ -396,7 +373,7 @@ Bitmap getIconFromUri (Uri uri) throws IOException { * @param resPath * Resource path as string */ - private String extractResourceName (String resPath) { + private String getBaseName (String resPath) { String drawable = resPath; if (drawable.contains("/")) { @@ -411,19 +388,39 @@ private String extractResourceName (String resPath) { } /** - * Extract extension of drawable resource from path. + * Returns a file located under the external cache dir of that app. * - * @param resPath - * Resource path as string + * @return + * File with a random UUID name */ - private String extractResourceExtension (String resPath) { - String extName = "png"; + private File getTmpFile () { + // If random UUID is not be enough see + // https://github.com/LukePulverenti/cordova-plugin-local-notifications/blob/267170db14044cbeff6f4c3c62d9b766b7a1dd62/src/android/notification/AssetUtil.java#L255 + return getTmpFile(UUID.randomUUID().toString()); + } - if (resPath.contains(".")) { - extName = resPath.substring(resPath.lastIndexOf('.')); + /** + * Returns a file located under the external cache dir of that app. + * + * @param name + * The name of the file + * @return + * File with the provided name + */ + private File getTmpFile (String name) { + File dir = context.getExternalCacheDir(); + + if (dir == null) { + Log.e("Asset", "Missing external cache dir"); + return null; } - return extName; + String storage = dir.toString() + STORAGE_FOLDER; + + //noinspection ResultOfMethodCallIgnored + new File(storage).mkdir(); + + return new File(storage, name); } /** From c00e96afdcc9cab29d131aa6c83b315b00f68881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 11 Dec 2015 17:47:08 +0100 Subject: [PATCH 19/51] Fixes #608 bad try/catch usage in getIconBitmap --- src/android/notification/Options.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index ca9e8f8db..7d2f38633 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -268,14 +268,14 @@ public Uri getSoundUri() { * Icon bitmap for the local notification. */ public Bitmap getIconBitmap() { - String icon = options.optString("icon", "icon"); Bitmap bmp; - try{ + try { Uri uri = Uri.parse(options.optString("iconUri")); bmp = assets.getIconFromUri(uri); } catch (Exception e){ - bmp = assets.getIconFromDrawable(icon); + e.printStackTrace(); + bmp = assets.getIconFromDrawable("icon"); } return bmp; From 341101621df9f194cbdd94647ff267dc86c33c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 11 Dec 2015 18:12:55 +0100 Subject: [PATCH 20/51] Prefer default style --- src/android/notification/Builder.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index 5397b0c61..d25382fc8 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -116,12 +116,8 @@ public Builder setClickActivity(Class activity) { */ public Notification build() { Uri sound = options.getSoundUri(); - NotificationCompat.BigTextStyle style; NotificationCompat.Builder builder; - style = new NotificationCompat.BigTextStyle() - .bigText(options.getText()); - builder = new NotificationCompat.Builder(context) .setDefaults(0) .setContentTitle(options.getTitle()) @@ -132,7 +128,6 @@ public Notification build() { .setLargeIcon(options.getIconBitmap()) .setAutoCancel(options.isAutoClear()) .setOngoing(options.isOngoing()) - .setStyle(style) .setLights(options.getLedColor(), 500, 500); if (sound != null) { From 4f9f3d0697cdb517c5bb854324a975d5520ac5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 13 Dec 2015 17:02:56 +0100 Subject: [PATCH 21/51] Made small icon on Android optional --- CHANGELOG.md | 1 + src/android/notification/Builder.java | 12 +++++++++--- src/android/notification/Options.java | 23 ++++++++++++++++++----- www/local-notification-util.js | 4 ++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c901b9466..32891b98a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Version 0.8.3 (not yet released) - New "quarter" intervall for iOS & Android +- Made small icon optional (Android) - Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index d25382fc8..a1c067a60 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -115,7 +115,8 @@ public Builder setClickActivity(Class activity) { * Creates the notification with all its options passed through JS. */ public Notification build() { - Uri sound = options.getSoundUri(); + Uri sound = options.getSoundUri(); + int smallIcon = options.getSmallIcon(); NotificationCompat.Builder builder; builder = new NotificationCompat.Builder(context) @@ -124,8 +125,6 @@ public Notification build() { .setContentText(options.getText()) .setNumber(options.getBadgeNumber()) .setTicker(options.getText()) - .setSmallIcon(options.getSmallIcon()) - .setLargeIcon(options.getIconBitmap()) .setAutoCancel(options.isAutoClear()) .setOngoing(options.isOngoing()) .setLights(options.getLedColor(), 500, 500); @@ -134,6 +133,13 @@ public Notification build() { builder.setSound(sound); } + if (smallIcon == 0) { + builder.setSmallIcon(options.getIcon()); + } else { + builder.setSmallIcon(options.getSmallIcon()); + builder.setLargeIcon(options.getIconBitmap()); + } + applyDeleteReceiver(builder); applyContentReceiver(builder); diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 7d2f38633..711b6beef 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -131,7 +131,7 @@ private void parseAssets() { if (options.has("iconUri")) return; - Uri iconUri = assets.parse(options.optString("icon", "icon")); + Uri iconUri = assets.parse(options.optString("icon", "icon")); Uri soundUri = assets.parseSound(options.optString("sound", null)); try { @@ -282,20 +282,33 @@ public Bitmap getIconBitmap() { } /** - * Small icon resource ID for the local notification. + * Icon resource ID for the local notification. */ - public int getSmallIcon () { - String icon = options.optString("smallIcon", ""); + public int getIcon () { + String icon = options.optString("icon", ""); int resId = assets.getResIdForDrawable(icon); if (resId == 0) { - resId = android.R.drawable.screen_background_dark; + resId = getSmallIcon(); + } + + if (resId == 0) { + resId = android.R.drawable.ic_popup_reminder; } return resId; } + /** + * Small icon resource ID for the local notification. + */ + public int getSmallIcon () { + String icon = options.optString("smallIcon", ""); + + return assets.getResIdForDrawable(icon); + } + /** * JSON object as string. */ diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 7e96b64c5..9380cb1be 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -60,8 +60,8 @@ exports.applyPlatformSpecificOptions = function () { switch (device.platform) { case 'Android': - defaults.icon = 'res://icon'; - defaults.smallIcon = 'res://ic_popup_reminder'; + defaults.icon = 'res://ic_popup_reminder'; + defaults.smallIcon = undefined; defaults.ongoing = false; defaults.autoClear = true; defaults.led = 'FFFFFF'; From da0a1f12f0d3d821f69f4b0adede43c842ec23c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 13 Dec 2015 17:03:26 +0100 Subject: [PATCH 22/51] Show empty rec as default icon --- src/android/notification/AssetUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/notification/AssetUtil.java b/src/android/notification/AssetUtil.java index eff93647b..66662e557 100644 --- a/src/android/notification/AssetUtil.java +++ b/src/android/notification/AssetUtil.java @@ -349,7 +349,7 @@ Bitmap getIconFromDrawable (String drawable) { } if (iconId == 0) { - iconId = android.R.drawable.ic_menu_info_details; + iconId = android.R.drawable.screen_background_dark_transparent; } return BitmapFactory.decodeResource(res, iconId); From ddc2296ca919b2b65c00d93a53df0c9a5b3ec51f Mon Sep 17 00:00:00 2001 From: Wen Luo Date: Tue, 15 Dec 2015 14:34:12 +0800 Subject: [PATCH 23/51] Update image raw src Update image src to site [ http://raw.githubusercontent.com ] And it is available to make npm page to show the right image. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6aea8cb1f..d21d2fd9b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Cordova Local-Notification Plugin The essential purpose of local notifications is to enable an application to inform its users that it has something for them — for example, a message or an upcoming appointment — when the application isn’t running in the foreground.
They are scheduled by an application and delivered on the same device. - + ### How they appear to the user Users see notifications in the following ways: From 93bec39063a58e64e56e62514fc7076e0cb7cfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 27 Dec 2015 14:06:50 +0100 Subject: [PATCH 24/51] Fixes #564 __NSCFNumber isEqualToString --- src/ios/UIApplication+APPLocalNotification.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ios/UIApplication+APPLocalNotification.m b/src/ios/UIApplication+APPLocalNotification.m index 60b6daac3..21fab3199 100644 --- a/src/ios/UIApplication+APPLocalNotification.m +++ b/src/ios/UIApplication+APPLocalNotification.m @@ -188,7 +188,9 @@ - (UILocalNotification*) localNotificationWithId:(NSNumber*)id for (UILocalNotification* notification in notifications) { - if ([notification.options.id isEqualToNumber:id]) { + NSString* fid = [NSString stringWithFormat:@"%@", notification.options.id]; + + if ([fid isEqualToString:[id stringValue]]) { return notification; } } From 3afb598550412b9b61a08bc3bb701280b6e04bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 15:27:08 +0100 Subject: [PATCH 25/51] Check if function is provided --- www/local-notification-core.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/local-notification-core.js b/www/local-notification-core.js index 03faa834e..ea8596193 100644 --- a/www/local-notification-core.js +++ b/www/local-notification-core.js @@ -441,6 +441,9 @@ exports.registerPermission = function (callback, scope) { */ exports.on = function (event, callback, scope) { + if (typeof callback !== "function") + return; + if (!this._listener[event]) { this._listener[event] = []; } From 5cb48c41516a5510836926193c2f19f88c49960c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 15:29:47 +0100 Subject: [PATCH 26/51] Added color option for Android --- CHANGELOG.md | 3 ++- src/android/notification/Builder.java | 5 +++++ src/android/notification/Options.java | 18 ++++++++++++++++++ www/local-notification-util.js | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32891b98a..85db26780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. #### Version 0.8.3 (not yet released) -- New "quarter" intervall for iOS & Android +- New `color` attribute for Android (Thanks to @Eusebius1920) +- New `quarter` intervall for iOS & Android - Made small icon optional (Android) - Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #732 loop between update and trigger (Android) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index a1c067a60..318ad48ab 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -127,12 +127,17 @@ public Notification build() { .setTicker(options.getText()) .setAutoCancel(options.isAutoClear()) .setOngoing(options.isOngoing()) + .setColor(options.getColor()) .setLights(options.getLedColor(), 500, 500); if (sound != null) { builder.setSound(sound); } + if (sound != null) { + builder.setSound(sound); + } + if (smallIcon == 0) { builder.setSmallIcon(options.getIcon()); } else { diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 711b6beef..96c67528c 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -27,6 +27,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; +import android.support.v4.app.NotificationCompat; import org.json.JSONException; import org.json.JSONObject; @@ -249,6 +250,23 @@ public int getLedColor() { return aRGB; } + /** + * @return + * The notification background color for the small icon + * Returns null, if no color is given. + */ + public Integer getColor() { + String hex = options.optString("color", null); + + if (hex == null) { + return NotificationCompat.COLOR_DEFAULT; + } + + int aRGB = Integer.parseInt(hex, 16); + + return aRGB + 0xFF000000; + } + /** * Sound file path for the local notification. */ diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 9380cb1be..4ffeb430b 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -65,6 +65,7 @@ exports.applyPlatformSpecificOptions = function () { defaults.ongoing = false; defaults.autoClear = true; defaults.led = 'FFFFFF'; + defaults.color = undefined; break; } From acece5de994496cc8499cbe324454ec3353f2fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 15:49:41 +0100 Subject: [PATCH 27/51] Use red as default LED color --- www/local-notification-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 4ffeb430b..4bcd5b520 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -64,7 +64,7 @@ exports.applyPlatformSpecificOptions = function () { defaults.smallIcon = undefined; defaults.ongoing = false; defaults.autoClear = true; - defaults.led = 'FFFFFF'; + defaults.led = 'FF0000'; defaults.color = undefined; break; } From 810ff01522c2914669eeaefc869be5c05a23a8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 15:50:56 +0100 Subject: [PATCH 28/51] Use system default LED color in case of --- src/android/notification/Builder.java | 6 +----- src/android/notification/Options.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index 318ad48ab..55eb1d34a 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -128,11 +128,7 @@ public Notification build() { .setAutoCancel(options.isAutoClear()) .setOngoing(options.isOngoing()) .setColor(options.getColor()) - .setLights(options.getLedColor(), 500, 500); - - if (sound != null) { - builder.setSound(sound); - } + .setLights(options.getLedColor(), 100, 100); if (sound != null) { builder.setSound(sound); diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 96c67528c..640194277 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -242,12 +242,15 @@ public String getTitle() { * The notification color for LED */ public int getLedColor() { - String hex = options.optString("led", "000000"); - int aRGB = Integer.parseInt(hex,16); + String hex = options.optString("led", null); - aRGB += 0xFF000000; + if (hex == null) { + return NotificationCompat.DEFAULT_LIGHTS; + } - return aRGB; + int aRGB = Integer.parseInt(hex, 16); + + return aRGB + 0xFF000000; } /** @@ -255,7 +258,7 @@ public int getLedColor() { * The notification background color for the small icon * Returns null, if no color is given. */ - public Integer getColor() { + public int getColor() { String hex = options.optString("color", null); if (hex == null) { From 0fee144746086e10972e00a0c9822e66edd448d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 16:28:32 +0100 Subject: [PATCH 29/51] Cleanup code --- src/android/notification/Options.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 640194277..7c71c324a 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -217,10 +217,7 @@ public Date getTriggerDate() { * Trigger date in milliseconds. */ public long getTriggerTime() { - //return Math.max( - // System.currentTimeMillis(), - return options.optLong("at", 0) * 1000; - //); + return options.optLong("at", 0) * 1000; } /** From 84267c09c970fdcccf768581a4c8e8ed851488bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Tue, 29 Dec 2015 17:08:57 +0100 Subject: [PATCH 30/51] Fixes #612 cannot update icon or sound --- CHANGELOG.md | 1 + src/android/notification/Manager.java | 2 +- src/android/notification/Options.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85db26780..676b4aa98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) - Fixed #682 crash while resuming app from notification (Android 6) +- Fixed #612 cannot update icon or sound (Android) - Fixed crashing `get(ID)` if notification doesn't exist #### Version 0.8.2 (08.11.2015) diff --git a/src/android/notification/Manager.java b/src/android/notification/Manager.java index 3505c9316..9af3c94f2 100644 --- a/src/android/notification/Manager.java +++ b/src/android/notification/Manager.java @@ -120,7 +120,7 @@ public Notification update (int id, JSONObject updates, Class receiver) { notification.getOptions().getDict(), updates); try { - options.putOpt("updated", true); + options.put("updated", true); } catch (JSONException ignore) {} return schedule(options, receiver); diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 7c71c324a..9d380d7c0 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -129,7 +129,7 @@ private void parseInterval() { */ private void parseAssets() { - if (options.has("iconUri")) + if (options.has("iconUri") && !options.optBoolean("updated")) return; Uri iconUri = assets.parse(options.optString("icon", "icon")); From 6d85bd69b79cfea7d9a33042832e6c5e7d2fd372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 31 Dec 2015 12:54:54 +0100 Subject: [PATCH 31/51] Windows platform does not use hooks anymore --- CHANGELOG.md | 1 + README.md | 6 -- plugin.xml | 12 ++-- scripts/windows/broadcastActivateEvent.js | 80 ----------------------- scripts/windows/setToastCapable.js | 63 ------------------ src/windows/LocalNotificationCore.js | 4 +- src/windows/LocalNotificationUtil.js | 4 +- 7 files changed, 8 insertions(+), 162 deletions(-) delete mode 100755 scripts/windows/broadcastActivateEvent.js delete mode 100755 scripts/windows/setToastCapable.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 676b4aa98..2437801f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - New `color` attribute for Android (Thanks to @Eusebius1920) - New `quarter` intervall for iOS & Android - Made small icon optional (Android) +- Windows platform does not use hooks anymore - Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) diff --git a/README.md b/README.md index d21d2fd9b..826747644 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,6 @@ [![npm version](https://badge.fury.io/js/de.appplant.cordova.plugin.local-notification.svg)](http://badge.fury.io/js/de.appplant.cordova.plugin.local-notification) [![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=L3HKQCD9UA35A "Donate once-off to this project using Paypal") -#### :bangbang: Please vote for these cordova-windows issues :bangbang: -1. https://issues.apache.org/jira/browse/CB-8674 _(Missing launch arguments)_ -2. https://issues.apache.org/jira/browse/CB-8946 _(Missing ToastCapable flag)_ - -Thanks a lot! - Cordova Local-Notification Plugin ================================= diff --git a/plugin.xml b/plugin.xml index a08dbc5a9..1d36a6f30 100644 --- a/plugin.xml +++ b/plugin.xml @@ -203,6 +203,10 @@ + + + + @@ -215,14 +219,6 @@ - - - - - - - -
diff --git a/scripts/windows/broadcastActivateEvent.js b/scripts/windows/broadcastActivateEvent.js deleted file mode 100755 index 40a90ca0a..000000000 --- a/scripts/windows/broadcastActivateEvent.js +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env node - -/* - * 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@ - */ - - -// Includes a snippet into the cordova-core js file -// to fire the activated event after device is ready - - -var fs = require('fs'), - rootdir = process.argv[2]; - -if (!rootdir) - return; - -/** - * 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 (filename, to_replace, replace_with) { - var data = fs.readFileSync(filename, 'utf8'), - result; - - if (data.indexOf(replace_with) > -1) - return; - - result = data.replace(to_replace, replace_with); - fs.writeFileSync(filename, result, 'utf8'); -} - -// Fires the activated event again after device is ready -var snippet = - "var activatedHandler = function (args) {" + - "channel.deviceready.subscribe(function () {" + - "app.queueEvent(args);" + - "});" + - "};" + - "app.addEventListener('activated', activatedHandler, false);" + - "document.addEventListener('deviceready', function () {" + - "app.removeEventListener('activated', activatedHandler);" + - "}, false);\n" + - " app.start();"; - -// Path to cordova-core js files where the snippet needs to be included -var files = [ - 'platforms/windows/www/cordova.js', - 'platforms/windows/platform_www/cordova.js' -]; - -// Includes the snippet before app.start() is called -for (var i = 0; i < files.length; i++) { - replace(files[i], 'app.start();', snippet); -} diff --git a/scripts/windows/setToastCapable.js b/scripts/windows/setToastCapable.js deleted file mode 100755 index 46b561024..000000000 --- a/scripts/windows/setToastCapable.js +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env node - -/* - * 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 sets ToastCapable on true to enable local-notifications - - -var fs = require('fs'), - rootdir = process.argv[2]; - -if (!rootdir) - return; - -/** - * 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 (filename, to_replace, replace_with) { - var data = fs.readFileSync(filename, 'utf8'), - result; - - if (data.indexOf('ToastCapable') > -1) - return; - - result = data.replace(new RegExp(to_replace, 'g'), replace_with); - - fs.writeFileSync(filename, result, 'utf8'); -} - -// Set ToastCapable for Windows Phone -replace('platforms/windows/package.phone.appxmanifest', ' Date: Thu, 31 Dec 2015 13:32:26 +0100 Subject: [PATCH 32/51] Fixes #569 getScheduled returns two items --- CHANGELOG.md | 1 + src/windows/LocalNotificationCore.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2437801f4..709659872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - Fixed #682 crash while resuming app from notification (Android 6) - Fixed #612 cannot update icon or sound (Android) - Fixed crashing `get(ID)` if notification doesn't exist +- Fixed #569 `getScheduled` returns two items per notification #### Version 0.8.2 (08.11.2015) - Submitted to npm diff --git a/src/windows/LocalNotificationCore.js b/src/windows/LocalNotificationCore.js index dbb593ea1..beb18148a 100644 --- a/src/windows/LocalNotificationCore.js +++ b/src/windows/LocalNotificationCore.js @@ -324,9 +324,12 @@ proxy.core = { ids = []; for (var i = 0; i < toasts.length; i++) { - var toast = toasts[i]; + var toast = toasts[i], + toastId = this.getToastId(toast); - ids.push(this.getToastId(toast)); + if (ids.indexOf(toastId) == -1) { + ids.push(toastId); + } } return ids; From 731ac9dfa71fc8cd54a79b8bb80241dc8b56a7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 31 Dec 2015 14:04:58 +0100 Subject: [PATCH 33/51] Only register permission once --- www/local-notification-core.js | 7 +++++++ www/local-notification-util.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/www/local-notification-core.js b/www/local-notification-core.js index ea8596193..f73e01548 100644 --- a/www/local-notification-core.js +++ b/www/local-notification-core.js @@ -414,6 +414,13 @@ exports.hasPermission = function (callback, scope) { * The callback function's scope */ exports.registerPermission = function (callback, scope) { + + if (this._registered) { + return this.hasPermission(callback, scope); + } else { + this._registered = true; + } + var fn = this.createCallbackFn(callback, scope); if (device.platform != 'iOS') { diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 4bcd5b520..5fd74a593 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -44,6 +44,9 @@ exports._defaults = { // listener exports._listener = {}; +// Registered permission flag +exports._registered = false; + /******** * UTIL * From f0ca49c4d4f4d20ab417eeab4e700634ac859ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 31 Dec 2015 14:43:21 +0100 Subject: [PATCH 34/51] Fixes #634 Option to skip permission check --- CHANGELOG.md | 4 ++- www/local-notification-core.js | 58 +++++++++++++++++++++++----------- www/local-notification.js | 18 +++++++---- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 709659872..875799672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - New `color` attribute for Android (Thanks to @Eusebius1920) - New `quarter` intervall for iOS & Android - Made small icon optional (Android) -- Windows platform does not use hooks anymore +- Windows platform works without hooks +- `update` checks for permission like `schedule` +- Fixed #634 option to skip permission check - Fixed #588 crash when basename & extension can't be extracted (Android) - Fixed #732 loop between update and trigger (Android) - Fixed #710 crash due to >500 notifications (Android) diff --git a/www/local-notification-core.js b/www/local-notification-core.js index f73e01548..afcc24575 100644 --- a/www/local-notification-core.js +++ b/www/local-notification-core.js @@ -55,52 +55,74 @@ exports.setDefaults = function (newDefaults) { /** * Schedule a new local notification. * - * @param {Object} opts + * @param {Object} msgs * The notification properties * @param {Function} callback * A function to be called after the notification has been canceled * @param {Object?} scope * The scope for the callback function + * @param {Object?} args + * skipPermission:true schedules the notifications immediatly without + * registering or checking for permission */ -exports.schedule = function (opts, callback, scope) { - this.registerPermission(function(granted) { +exports.schedule = function (msgs, callback, scope, args) { + var fn = function(granted) { - if (!granted) - return; + if (!granted) return; - var notifications = Array.isArray(opts) ? opts : [opts]; + var notifications = Array.isArray(msgs) ? msgs : [msgs]; for (var i = 0; i < notifications.length; i++) { - var properties = notifications[i]; + var notification = notifications[i]; - this.mergeWithDefaults(properties); - this.convertProperties(properties); + this.mergeWithDefaults(notification); + this.convertProperties(notification); } this.exec('schedule', notifications, callback, scope); - }, this); + }; + + if (args && args.skipPermission) { + fn.call(this, true); + } else { + this.registerPermission(fn, this); + } }; /** * Update existing notifications specified by IDs in options. * - * @param {Object} options + * @param {Object} notifications * The notification properties to update * @param {Function} callback * A function to be called after the notification has been updated * @param {Object?} scope * The scope for the callback function + * @param {Object?} args + * skipPermission:true schedules the notifications immediatly without + * registering or checking for permission */ -exports.update = function (opts, callback, scope) { - var notifications = Array.isArray(opts) ? opts : [opts]; +exports.update = function (msgs, callback, scope, args) { + var fn = function(granted) { - for (var i = 0; i < notifications.length; i++) { - var properties = notifications[i]; + if (!granted) return; - this.convertProperties(properties); - } + var notifications = Array.isArray(msgs) ? msgs : [msgs]; + + for (var i = 0; i < notifications.length; i++) { + var notification = notifications[i]; - this.exec('update', notifications, callback, scope); + this.convertProperties(notification); + } + + this.exec('update', notifications, callback, scope); + }; + + if (args && args.skipPermission) { + fn.call(this, true); + } else { + this.registerPermission(fn, this); + } }; /** diff --git a/www/local-notification.js b/www/local-notification.js index 9e9bd2844..f8622a5fd 100644 --- a/www/local-notification.js +++ b/www/local-notification.js @@ -47,29 +47,35 @@ exports.setDefaults = function (defaults) { /** * Schedule a new local notification. * - * @param {Object} opts + * @param {Object} notifications * The notification properties * @param {Function} callback * A function to be called after the notification has been canceled * @param {Object?} scope * The scope for the callback function + * @param {Object?} args + * skipPermission:true schedules the notifications immediatly without + * registering or checking for permission */ -exports.schedule = function (opts, callback, scope) { - this.core.schedule(opts, callback, scope); +exports.schedule = function (notifications, callback, scope, args) { + this.core.schedule(notifications, callback, scope, args); }; /** * Update existing notifications specified by IDs in options. * - * @param {Object} options + * @param {Object} notifications * The notification properties to update * @param {Function} callback * A function to be called after the notification has been updated * @param {Object?} scope * The scope for the callback function + * @param {Object?} args + * skipPermission:true schedules the notifications immediatly without + * registering or checking for permission */ -exports.update = function (opts, callback, scope) { - this.core.update(opts, callback, scope); +exports.update = function (notifications, callback, scope, args) { + this.core.update(notifications, callback, scope, args); }; /** From 0ae10b80cb11994d6a340856c4e4375212d39cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 31 Dec 2015 15:36:04 +0100 Subject: [PATCH 35/51] Experimental decrease time-frame for trigger event --- CHANGELOG.md | 1 + src/ios/APPLocalNotification.m | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 875799672..6afe2cccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - New `color` attribute for Android (Thanks to @Eusebius1920) - New `quarter` intervall for iOS & Android - Made small icon optional (Android) +- Decreased time-frame for trigger event (iOS) - Windows platform works without hooks - `update` checks for permission like `schedule` - Fixed #634 option to skip permission check diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 9772e5ef3..022e8688e 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -571,12 +571,11 @@ - (void) didReceiveLocalNotification:(NSNotification*)localNotification { UILocalNotification* notification = [localNotification object]; - if ([notification userInfo] == NULL || [notification wasUpdated] ) + if ([notification userInfo] == NULL || [notification wasUpdated]) return; NSTimeInterval timeInterval = [notification timeIntervalSinceLastTrigger]; - - NSString* event = (timeInterval <= 1 && deviceready) ? @"trigger" : @"click"; + NSString* event = timeInterval < 0.2 && deviceready ? @"trigger" : @"click"; [self fireEvent:event notification:notification]; From 80dc6caa5484806e2ba78e40c019e1e1e110e0dc Mon Sep 17 00:00:00 2001 From: Brian Keith Smith Date: Thu, 31 Dec 2015 09:38:39 -0600 Subject: [PATCH 36/51] expect the every option to always be a string on iOS. display a warning if it is not. --- www/local-notification-util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 5fd74a593..5f824c436 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -172,6 +172,16 @@ exports.convertProperties = function (options) { options.data = JSON.stringify(options.data); } + if (options.every) + if (device.platform == 'iOS' && typeof options.every != 'string') { + options.every = this.getDefaults().every; + var warning = 'Every option is not a string: ' + options.id; + warning += '. Expects one of: second, minute, hour, day, week, '; + warning += 'month, year on iOS.'; + console.warn(warning); + } + } + return options; }; From 9dd5e06f4d61a9856861dfee6e42f13f3c751ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 1 Jan 2016 19:24:37 +0100 Subject: [PATCH 37/51] Support cordova-ios@4 and WKWebView Engine --- CHANGELOG.md | 1 + plugin.xml | 3 +-- src/ios/APPLocalNotification.m | 22 +--------------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6afe2cccd..9cc053053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. #### Version 0.8.3 (not yet released) +- Support cordova-ios@4 and the new WKWebView Engine - New `color` attribute for Android (Thanks to @Eusebius1920) - New `quarter` intervall for iOS & Android - Made small icon optional (Android) diff --git a/plugin.xml b/plugin.xml index 1d36a6f30..85c75769b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,12 +21,11 @@ - - + diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 022e8688e..03a2d23e5 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -25,7 +25,6 @@ #import "APPLocalNotificationOptions.h" #import "UIApplication+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h" -#import "AppDelegate+APPRegisterUserNotificationSettings.h" @interface APPLocalNotification () @@ -615,8 +614,7 @@ - (void) didFinishLaunchingWithOptions:(NSNotification*)notification */ - (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings { - if (_command) - { + if (_command) { [self hasPermission:_command]; _command = NULL; } @@ -630,25 +628,7 @@ - (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settin */ - (void) pluginInitialize { - NSNotificationCenter* center = [NSNotificationCenter - defaultCenter]; - eventQueue = [[NSMutableArray alloc] init]; - - [center addObserver:self - selector:@selector(didReceiveLocalNotification:) - name:CDVLocalNotification - object:nil]; - - [center addObserver:self - selector:@selector(didFinishLaunchingWithOptions:) - name:UIApplicationDidFinishLaunchingNotification - object:nil]; - - [center addObserver:self - selector:@selector(didRegisterUserNotificationSettings:) - name:UIApplicationRegisterUserNotificationSettings - object:nil]; } /** From 1ddf040193c6b83ae09ab43f07a667820255e328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 3 Jan 2016 12:31:19 +0100 Subject: [PATCH 38/51] Fixed bug in getType --- src/android/notification/Notification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/notification/Notification.java b/src/android/notification/Notification.java index d9aaf7271..ad363788d 100644 --- a/src/android/notification/Notification.java +++ b/src/android/notification/Notification.java @@ -156,7 +156,7 @@ protected boolean isUpdate (boolean keepFlag) { * Notification type can be one of pending or scheduled. */ public Type getType () { - return isTriggered() ? Type.TRIGGERED : Type.SCHEDULED; + return isScheduled() ? Type.SCHEDULED : Type.TRIGGERED; } /** From 0a44a11ac69125f782817accd14b0df4a006a7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 3 Jan 2016 12:33:56 +0100 Subject: [PATCH 39/51] Fixes #700 notifications appears on bootup --- CHANGELOG.md | 1 + src/android/RestoreReceiver.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc053053..8d9d9a66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo - Fixed #612 cannot update icon or sound (Android) - Fixed crashing `get(ID)` if notification doesn't exist - Fixed #569 `getScheduled` returns two items per notification +- Fixed #700 notifications appears on bootup #### Version 0.8.2 (08.11.2015) - Submitted to npm diff --git a/src/android/RestoreReceiver.java b/src/android/RestoreReceiver.java index 7de4e3282..675ea7cab 100644 --- a/src/android/RestoreReceiver.java +++ b/src/android/RestoreReceiver.java @@ -44,6 +44,8 @@ public class RestoreReceiver extends AbstractRestoreReceiver { public void onRestore (Notification notification) { if (notification.isScheduled()) { notification.schedule(); + } else { + notification.cancel(); } } From ed859d07c8968d6fa52f61a6afc132ea32ac39f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 3 Jan 2016 13:24:53 +0100 Subject: [PATCH 40/51] Prepare release of v0.8.3 --- CHANGELOG.md | 39 ++++++++++++++----------- README.md | 5 ++-- package.json | 81 +++++++++++++++++++++++++++++++--------------------- plugin.xml | 1 + 4 files changed, 75 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d9d9a66b..e595e235a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,23 +3,28 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. -#### Version 0.8.3 (not yet released) -- Support cordova-ios@4 and the new WKWebView Engine -- New `color` attribute for Android (Thanks to @Eusebius1920) -- New `quarter` intervall for iOS & Android -- Made small icon optional (Android) -- Decreased time-frame for trigger event (iOS) -- Windows platform works without hooks -- `update` checks for permission like `schedule` -- Fixed #634 option to skip permission check -- Fixed #588 crash when basename & extension can't be extracted (Android) -- Fixed #732 loop between update and trigger (Android) -- Fixed #710 crash due to >500 notifications (Android) -- Fixed #682 crash while resuming app from notification (Android 6) -- Fixed #612 cannot update icon or sound (Android) -- Fixed crashing `get(ID)` if notification doesn't exist -- Fixed #569 `getScheduled` returns two items per notification -- Fixed #700 notifications appears on bootup +#### Version 0.8.3 (03.01.2016) +- Platform enhancements + - Support for the `Crosswalk Engine` + - Support for `cordova-ios@4` and the `WKWebView Engine` + - Support for `cordova-windows@4` and `Windows 10` without using hooks +- Enhancements + - New `color` attribute for Android (Thanks to @Eusebius1920) + - New `quarter` intervall for iOS & Android + - `smallIcon` is optional (Android) + - `update` checks for permission like _schedule_ + - Decreased time-frame for trigger event (iOS) + - Force `every:` to be a string on iOS +- Bug fixes + - Fixed #634 option to skip permission check + - Fixed #588 crash when basename & extension can't be extracted (Android) + - Fixed #732 loop between update and trigger (Android) + - Fixed #710 crash due to >500 notifications (Android) + - Fixed #682 crash while resuming app from notification (Android 6) + - Fixed #612 cannot update icon or sound (Android) + - Fixed crashing get(ID) if notification doesn't exist + - Fixed #569 getScheduled returns two items per notification + - Fixed #700 notifications appears on bootup #### Version 0.8.2 (08.11.2015) - Submitted to npm diff --git a/README.md b/README.md index 826747644..20f853df4 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ For example, applications that depend on servers for messages or data can poll t ## Supported Platforms The current 0.8 branch supports the following platforms: -- __iOS__ _(including iOS8)_
+- __iOS__ _(>= 8)_
- __Android__ _(SDK >=7)_ - __Windows 8.1__ _(added with v0.8.2)_ - __Windows Phone 8.1__ _(added with v0.8.2)_ +- __Windows 10__ _(added with v0.8.3)_ Find out more informations [here][wiki_platforms] in our wiki. @@ -114,7 +115,7 @@ Thank you! This software is released under the [Apache 2.0 License][apache2_license]. -© 2013-2015 appPlant UG, Inc. All rights reserved +© 2013-2016 appPlant UG, Inc. All rights reserved [cordova]: https://cordova.apache.org diff --git a/package.json b/package.json index 19ccf1e41..1db448f72 100644 --- a/package.json +++ b/package.json @@ -1,35 +1,52 @@ { - "version": "0.8.2", - "name": "de.appplant.cordova.plugin.local-notification", - "cordova_name": "Cordova LocalNotification Plugin", - "description": "Cordova plugin to schedule and query local notifications", - "author": "Sebastián Katzer", - "license": "Apache 2.0", - "repo": "https://github.com/katzer/cordova-plugin-local-notifications.git", - "issue": "https://github.com/katzer/cordova-plugin-local-notifications/issues", - "keywords": [ - "appplant", - "notification", - "local notification", - "cordova", - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "cordova-windows" - ], - "platforms": [ - "ios", - "android", - "windows" - ], - "engines": [ - { - "name": "cordova", - "version": ">=3.6.0" - } - ], - "repository": { - "type": "git", - "url": "https://github.com/katzer/cordova-plugin-local-notifications.git" + "name": "de.appplant.cordova.plugin.local-notification", + "cordova_name": "Cordova LocalNotification Plugin", + "version": "0.8.2", + "description": "Schedules and queries for local notifications", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/katzer/cordova-plugin-local-notifications.git" + }, + "keywords": [ + "appplant", + "notification", + "local notification", + "cordova", + "ecosystem:cordova", + "cordova-android", + "cordova-ios", + "cordova-windows" + ], + "platforms": [ + "ios", + "android", + "windows" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.6.0" + }, + { + "name": "cordova-plugman", + "version": ">=4.3.0" + }, + { + "name": "cordova-windows", + "version": ">=4.2.0" } + ], + "dependencies": { + "cordova-plugin-device": "*", + "cordova-plugin-app-event": ">=1.1.0" + }, + "author": "Sebastián Katzer", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/katzer/cordova-plugin-local-notifications/issues" + }, + "homepage": "https://github.com/katzer/cordova-plugin-local-notifications#readme" } diff --git a/plugin.xml b/plugin.xml index 85c75769b..1a727c608 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,6 +21,7 @@ + From 3c9564c4b12bed127c267037c67498fde69e535e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 3 Jan 2016 14:08:50 +0100 Subject: [PATCH 41/51] Release v0.8.3 --- package.json | 2 +- plugin.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1db448f72..bef4c940c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "de.appplant.cordova.plugin.local-notification", "cordova_name": "Cordova LocalNotification Plugin", - "version": "0.8.2", + "version": "0.8.3", "description": "Schedules and queries for local notifications", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/plugin.xml b/plugin.xml index 1a727c608..b415b030c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.8.3"> LocalNotification From 6f59f80aaf1e1214484509245afca302db1aa17a Mon Sep 17 00:00:00 2001 From: Zeno Foltin Date: Sun, 3 Jan 2016 16:44:42 +0000 Subject: [PATCH 42/51] Fix missing { --- www/local-notification-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 5f824c436..f2a0f3a5c 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -172,7 +172,7 @@ exports.convertProperties = function (options) { options.data = JSON.stringify(options.data); } - if (options.every) + if (options.every) { if (device.platform == 'iOS' && typeof options.every != 'string') { options.every = this.getDefaults().every; var warning = 'Every option is not a string: ' + options.id; From 3e611de2eb02fe12781ca72a5225fb3ea2fec13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Mon, 4 Jan 2016 20:37:31 +0100 Subject: [PATCH 43/51] Release v0.8.4 --- CHANGELOG.md | 4 ++++ package.json | 2 +- plugin.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e595e235a..87716553a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ChangeLog Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information. +#### Version 0.8.4 (04.01.2016) +- Bug fixes + - SyntaxError: missing ) after argument list + #### Version 0.8.3 (03.01.2016) - Platform enhancements - Support for the `Crosswalk Engine` diff --git a/package.json b/package.json index bef4c940c..f4d685d29 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "de.appplant.cordova.plugin.local-notification", "cordova_name": "Cordova LocalNotification Plugin", - "version": "0.8.3", + "version": "0.8.4", "description": "Schedules and queries for local notifications", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/plugin.xml b/plugin.xml index b415b030c..7536568a9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.8.4"> LocalNotification From d9ac383bcce9f484df2b925a56bbfb4efbd53ee6 Mon Sep 17 00:00:00 2001 From: Lenny Kean Date: Tue, 12 Apr 2016 08:41:34 -0500 Subject: [PATCH 44/51] fixed reference error when calling un function (#847) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit removed unused ‘scope’ variable from un function. --- www/local-notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/local-notification.js b/www/local-notification.js index f8622a5fd..fc647a6e3 100644 --- a/www/local-notification.js +++ b/www/local-notification.js @@ -372,5 +372,5 @@ exports.on = function (event, callback, scope) { * The function to be exec as callback */ exports.un = function (event, callback) { - this.core.un(event, callback, scope); + this.core.un(event, callback); }; From ec674ea79325339cf0d7ceb6c18d99e6ccf6acf1 Mon Sep 17 00:00:00 2001 From: Alexandre Laurent Date: Tue, 12 Apr 2016 15:44:11 +0200 Subject: [PATCH 45/51] Android: Ability to disable notification led (#864) --- src/android/notification/Builder.java | 8 ++++++-- src/android/notification/Options.java | 2 +- www/local-notification-util.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index 55eb1d34a..e60858b11 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -117,6 +117,7 @@ public Builder setClickActivity(Class activity) { public Notification build() { Uri sound = options.getSoundUri(); int smallIcon = options.getSmallIcon(); + int ledColor = options.getLedColor(); NotificationCompat.Builder builder; builder = new NotificationCompat.Builder(context) @@ -127,8 +128,11 @@ public Notification build() { .setTicker(options.getText()) .setAutoCancel(options.isAutoClear()) .setOngoing(options.isOngoing()) - .setColor(options.getColor()) - .setLights(options.getLedColor(), 100, 100); + .setColor(options.getColor()); + + if (ledColor != 0) { + builder.setLights(ledColor, 100, 100); + } if (sound != null) { builder.setSound(sound); diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 9d380d7c0..fa2ec849f 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -242,7 +242,7 @@ public int getLedColor() { String hex = options.optString("led", null); if (hex == null) { - return NotificationCompat.DEFAULT_LIGHTS; + return 0; } int aRGB = Integer.parseInt(hex, 16); diff --git a/www/local-notification-util.js b/www/local-notification-util.js index f2a0f3a5c..21cc40d3a 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -67,7 +67,7 @@ exports.applyPlatformSpecificOptions = function () { defaults.smallIcon = undefined; defaults.ongoing = false; defaults.autoClear = true; - defaults.led = 'FF0000'; + defaults.led = undefined; defaults.color = undefined; break; } From f67116e18fdd8257e20674501797f0d881d1db33 Mon Sep 17 00:00:00 2001 From: Jonathan Price Date: Tue, 12 Apr 2016 14:45:01 +0100 Subject: [PATCH 46/51] Prepend default icon with missing prefix (#868) * assets.parse expects prefix of res://, file://, or http://. --- src/android/notification/Options.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index fa2ec849f..61234d60f 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -132,7 +132,7 @@ private void parseAssets() { if (options.has("iconUri") && !options.optBoolean("updated")) return; - Uri iconUri = assets.parse(options.optString("icon", "icon")); + Uri iconUri = assets.parse(options.optString("icon", "res://icon")); Uri soundUri = assets.parseSound(options.optString("sound", null)); try { From a3f2be443b4d4539557611b5081453a7bfd1be46 Mon Sep 17 00:00:00 2001 From: akuraru Date: Tue, 12 Apr 2016 22:48:04 +0900 Subject: [PATCH 47/51] can compile without the precompiled header (#927) --- src/ios/APPLocalNotificationOptions.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ios/APPLocalNotificationOptions.h b/src/ios/APPLocalNotificationOptions.h index 73c3ef758..627ba00f7 100644 --- a/src/ios/APPLocalNotificationOptions.h +++ b/src/ios/APPLocalNotificationOptions.h @@ -20,6 +20,9 @@ * * @APPPLANT_LICENSE_HEADER_END@ */ + +#import +#import @interface APPLocalNotificationOptions : NSObject From 2253a4601e489e71a4bbd6875b32f8960981506f Mon Sep 17 00:00:00 2001 From: jokiamo Date: Mon, 25 Jul 2016 11:31:31 +0200 Subject: [PATCH 48/51] Update APPLocalNotification.m (#1042) Quick fix for ios10beta --- src/ios/APPLocalNotification.m | 65 ++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 03a2d23e5..93f4569a2 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -25,6 +25,7 @@ #import "APPLocalNotificationOptions.h" #import "UIApplication+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h" +@import UserNotifications; @interface APPLocalNotification () @@ -691,27 +692,53 @@ - (void) fireEvent:(NSString*)event */ - (void) fireEvent:(NSString*)event notification:(UILocalNotification*)notification { - NSString* js; - NSString* params = [NSString stringWithFormat: - @"\"%@\"", self.applicationState]; - - if (notification) { - NSString* args = [notification encodeToJSON]; - - params = [NSString stringWithFormat: - @"%@,'%@'", - args, self.applicationState]; - } - - js = [NSString stringWithFormat: - @"cordova.plugins.notification.local.core.fireEvent('%@', %@)", - event, params]; - - if (deviceready) { - [self.commandDelegate evalJs:js]; + + if (IsAtLeastiOSVersion(@"10.0")) { + UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; + content.title = [NSString localizedUserNotificationStringForKey:notification.alertTitle arguments:nil]; + content.body = [NSString localizedUserNotificationStringForKey:notification.alertBody + arguments:nil]; + content.sound = [UNNotificationSound defaultSound]; + + /// 4. update application icon badge numberß + //content.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1); + // Deliver the notification in five seconds. + UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger + triggerWithTimeInterval:1.f repeats:NO]; + UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" + content:content trigger:trigger]; + /// 3. schedule localNotification + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { + if (!error) { + NSLog(@"add NotificationRequest succeeded!"); + } + }]; } else { - [self.eventQueue addObject:js]; + + NSString* js; + NSString* params = [NSString stringWithFormat: + @"\"%@\"", self.applicationState]; + + if (notification) { + NSString* args = [notification encodeToJSON]; + + params = [NSString stringWithFormat: + @"%@,'%@'", + args, self.applicationState]; + } + + js = [NSString stringWithFormat: + @"cordova.plugins.notification.local.core.fireEvent('%@', %@)", + event, params]; + + if (deviceready) { + [self.commandDelegate evalJs:js]; + } else { + [self.eventQueue addObject:js]; + } } + } @end From da094647b5f79e8d561dd2b1093e489238644787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Wed, 27 Jul 2016 16:30:23 +0200 Subject: [PATCH 49/51] Revert "Update APPLocalNotification.m iOS10beta" (#1055) --- src/ios/APPLocalNotification.m | 65 ++++++++++------------------------ 1 file changed, 19 insertions(+), 46 deletions(-) diff --git a/src/ios/APPLocalNotification.m b/src/ios/APPLocalNotification.m index 93f4569a2..03a2d23e5 100644 --- a/src/ios/APPLocalNotification.m +++ b/src/ios/APPLocalNotification.m @@ -25,7 +25,6 @@ #import "APPLocalNotificationOptions.h" #import "UIApplication+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h" -@import UserNotifications; @interface APPLocalNotification () @@ -692,53 +691,27 @@ - (void) fireEvent:(NSString*)event */ - (void) fireEvent:(NSString*)event notification:(UILocalNotification*)notification { - - if (IsAtLeastiOSVersion(@"10.0")) { - UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; - content.title = [NSString localizedUserNotificationStringForKey:notification.alertTitle arguments:nil]; - content.body = [NSString localizedUserNotificationStringForKey:notification.alertBody - arguments:nil]; - content.sound = [UNNotificationSound defaultSound]; - - /// 4. update application icon badge numberß - //content.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1); - // Deliver the notification in five seconds. - UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger - triggerWithTimeInterval:1.f repeats:NO]; - UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" - content:content trigger:trigger]; - /// 3. schedule localNotification - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { - if (!error) { - NSLog(@"add NotificationRequest succeeded!"); - } - }]; + NSString* js; + NSString* params = [NSString stringWithFormat: + @"\"%@\"", self.applicationState]; + + if (notification) { + NSString* args = [notification encodeToJSON]; + + params = [NSString stringWithFormat: + @"%@,'%@'", + args, self.applicationState]; + } + + js = [NSString stringWithFormat: + @"cordova.plugins.notification.local.core.fireEvent('%@', %@)", + event, params]; + + if (deviceready) { + [self.commandDelegate evalJs:js]; } else { - - NSString* js; - NSString* params = [NSString stringWithFormat: - @"\"%@\"", self.applicationState]; - - if (notification) { - NSString* args = [notification encodeToJSON]; - - params = [NSString stringWithFormat: - @"%@,'%@'", - args, self.applicationState]; - } - - js = [NSString stringWithFormat: - @"cordova.plugins.notification.local.core.fireEvent('%@', %@)", - event, params]; - - if (deviceready) { - [self.commandDelegate evalJs:js]; - } else { - [self.eventQueue addObject:js]; - } + [self.eventQueue addObject:js]; } - } @end From 366557fdbe54ff92e030210c5e405d6d57a5f4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Thu, 4 Aug 2016 10:24:51 +0200 Subject: [PATCH 50/51] Quick fix plugman version issue --- plugin.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 7536568a9..250391e0e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -20,7 +20,8 @@ - + + From 327f01f9e407b13c236b96e3353c86552185ee89 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 5 Sep 2016 08:44:55 +0200 Subject: [PATCH 51/51] Allow configuring Android led time (#1080) Default time extended from 100 to 1000 ms --- src/android/notification/Builder.java | 2 +- src/android/notification/Options.java | 36 +++++++++++++++++++++++++++ www/local-notification-util.js | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/android/notification/Builder.java b/src/android/notification/Builder.java index e60858b11..ab8db3dce 100644 --- a/src/android/notification/Builder.java +++ b/src/android/notification/Builder.java @@ -131,7 +131,7 @@ public Notification build() { .setColor(options.getColor()); if (ledColor != 0) { - builder.setLights(ledColor, 100, 100); + builder.setLights(ledColor, options.getLedOnTime(), options.getLedOffTime()); } if (sound != null) { diff --git a/src/android/notification/Options.java b/src/android/notification/Options.java index 61234d60f..e78035958 100644 --- a/src/android/notification/Options.java +++ b/src/android/notification/Options.java @@ -250,6 +250,42 @@ public int getLedColor() { return aRGB + 0xFF000000; } + /** + * @return + * The time that the LED should be on (in milliseconds). + */ + public int getLedOnTime() { + String timeOn = options.optString("ledOnTime", null); + + if (timeOn == null) { + return 1000; + } + + try { + return Integer.parseInt(timeOn); + } catch (NumberFormatException e) { + return 1000; + } + } + + /** + * @return + * The time that the LED should be off (in milliseconds). + */ + public int getLedOffTime() { + String timeOff = options.optString("ledOffTime", null); + + if (timeOff == null) { + return 1000; + } + + try { + return Integer.parseInt(timeOff); + } catch (NumberFormatException e) { + return 1000; + } + } + /** * @return * The notification background color for the small icon diff --git a/www/local-notification-util.js b/www/local-notification-util.js index 21cc40d3a..e87409a66 100644 --- a/www/local-notification-util.js +++ b/www/local-notification-util.js @@ -68,6 +68,8 @@ exports.applyPlatformSpecificOptions = function () { defaults.ongoing = false; defaults.autoClear = true; defaults.led = undefined; + defaults.ledOnTime = undefined; + defaults.ledOffTime = undefined; defaults.color = undefined; break; }