Skip to content

Commit

Permalink
Can't set priority for Android heads-up notification #114
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 11, 2019
1 parent 004ccd6 commit c44e661
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/local-notifications-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export interface ScheduleOptions {
*/
forceShowWhenInForeground?: boolean;

priority?: number;

/**
* Buttons or text input.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/local-notifications.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Binary file modified src/platforms/android/app-release.aar
Binary file not shown.

0 comments on commit c44e661

Please sign in to comment.