diff --git a/README.md b/README.md index 9744a83..2953a62 100755 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ You can pass several options to this function, everything is optional: |`ongoing` |Default is (`false`). Set whether this is an `ongoing` notification. Ongoing notifications cannot be dismissed by the user, so your application must take care of canceling them. (**Android Only**) | |`channel` |Default is (`Channel`). Set the channel name for Android API >= 26, which is shown when the user longpresses a notification. (**Android Only**) | |`forceShowWhenInForeground` |Default is `false`. Set to `true` to always show the notification. Note that on iOS < 10 this is ignored (the notification is not shown), and on newer Androids it's currently ignored as well (the notification always shows, per platform default). | +|`priority` |Default is `0`. Will override `forceShowWhenInForeground` if set. This can be set to `2` for Android "heads-up" notifications. See [#114](https://github.com/EddyVerbruggen/nativescript-local-notifications/issues/114) for details. | |`actions` |Add an array of `NotificationAction` objects (see below) to add buttons or text input to a notification. | |`notificationLed` |Enable the notification LED light on Android (if supported by the device), this can be either: `true` (if you want to use the default color), or a custom color for the notification LED light (if supported by the device). (**Android Only**). Default not set.| diff --git a/native-src/android/app/src/main/java/com/telerik/localnotifications/Builder.java b/native-src/android/app/src/main/java/com/telerik/localnotifications/Builder.java index 6d32f4a..24e9fef 100644 --- a/native-src/android/app/src/main/java/com/telerik/localnotifications/Builder.java +++ b/native-src/android/app/src/main/java/com/telerik/localnotifications/Builder.java @@ -68,7 +68,7 @@ static Notification build(JSONObject options, Context context, int notificationI .setNumber(options.optInt("badge")) .setColor(options.optInt("color")) .setOngoing(options.optBoolean("ongoing")) - .setPriority(options.optBoolean("forceShowWhenInForeground") ? 1 : 0) + .setPriority(options.optInt("priority", options.optBoolean("forceShowWhenInForeground") ? 1 : 0)) .setTicker(options.optString("ticker", null)); // Let the OS handle the default value for the ticker. final Object thumbnail = options.opt("thumbnail"); diff --git a/src/local-notifications-common.ts b/src/local-notifications-common.ts index 88807f4..e548a67 100755 --- a/src/local-notifications-common.ts +++ b/src/local-notifications-common.ts @@ -178,6 +178,8 @@ export interface ScheduleOptions { */ forceShowWhenInForeground?: boolean; + priority?: number; + /** * Buttons or text input. */ diff --git a/src/local-notifications.ios.ts b/src/local-notifications.ios.ts index 149d9d4..e4bda37 100755 --- a/src/local-notifications.ios.ts +++ b/src/local-notifications.ios.ts @@ -136,8 +136,9 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements content.sound = UNNotificationSound.defaultSound; } - const userInfoDict = new NSMutableDictionary({capacity: 1}); + const userInfoDict = new NSMutableDictionary({capacity: 2}); userInfoDict.setObjectForKey(options.forceShowWhenInForeground, "forceShowWhenInForeground"); + userInfoDict.setObjectForKey(options.priority, "priority"); content.userInfo = userInfoDict; // Notification trigger and repeat @@ -524,7 +525,7 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot this.receivedInForeground = true; - if (notification.request.content.userInfo.valueForKey("forceShowWhenInForeground")) { + if (notification.request.content.userInfo.valueForKey("forceShowWhenInForeground") || notification.request.content.userInfo.valueForKey("priority")) { completionHandler(UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert); } else { completionHandler(UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound); diff --git a/src/package.json b/src/package.json index 7c392c3..d0db952 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-local-notifications", - "version": "4.1.1", + "version": "4.1.2", "description": "The Local Notifications plugin allows your app to show notifications when the app is not running. Just like remote push notifications, but a few orders of magnitude easier to set up.", "main": "local-notifications", "typings": "index.d.ts", diff --git a/src/platforms/android/app-release.aar b/src/platforms/android/app-release.aar index 3ff0ed8..2a81721 100644 Binary files a/src/platforms/android/app-release.aar and b/src/platforms/android/app-release.aar differ