Quellcode durchsuchen

CHANGE: New >foreground< option, false by default
Before on iOS all notification came up in foreground, thats different
now with this commit

Sebastián Katzer vor 8 Jahren
Ursprung
Commit
9578246df6

+ 3 - 2
README.md

@@ -68,7 +68,8 @@ The plugin creates the object `cordova.plugins.notification.local` and is access
 ```js
 cordova.plugins.notification.local.schedule({
     title: 'My first notification',
-    text: 'Thats pretty easy...'
+    text: 'Thats pretty easy...',
+    foreground: true
 });
 ```
 
@@ -93,7 +94,7 @@ A notification does have a set of configurable properties. Not all of them are s
 | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ |
 | id            | data          | actionGroupId | summary       | led           | showWhen      | channel       | actions       |
 | text          | icon          | attachments   | smallIcon     | color         | defaults      | launch        | groupSummary  |
-| title         | silent        | progressBar   | sticky        | vibrate       | priority      | mediaSession  | 
+| title         | silent        | progressBar   | sticky        | vibrate       | priority      | mediaSession  | foreground    |
 | sound         | trigger       | group         | autoClear     | lockscreen    | number        | badge         |
 
 For their default values see:

+ 6 - 2
src/ios/APPLocalNotification.m

@@ -504,14 +504,18 @@
         willPresentNotification:(UNNotification *)notification
           withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
 {
+    APPNotificationOptions* options = notification.request.options;
+
     if (![notification.request wasUpdated]) {
         [self fireEvent:@"trigger" notification:notification.request];
     }
 
-    if (notification.request.options.silent) {
+    if (options.silent) {
         completionHandler(UNNotificationPresentationOptionNone);
-    } else {
+    } else if (!isActive || options.priority > 0) {
         completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
+    } else {
+        completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound);
     }
 }
 

+ 1 - 0
src/ios/APPNotificationOptions.h

@@ -31,6 +31,7 @@
 @property (readonly, getter=badge)       NSNumber*            badge;
 @property (readonly, getter=text)        NSString*            text;
 @property (readonly, getter=silent)      BOOL                 silent;
+@property (readonly, getter=priority)    int                  priority;
 @property (readonly, getter=sound)       UNNotificationSound* sound;
 @property (readonly, getter=userInfo)    NSDictionary*        userInfo;
 @property (readonly, getter=actions)     NSArray<UNNotificationAction *> * actions;

+ 11 - 1
src/ios/APPNotificationOptions.m

@@ -115,7 +115,7 @@
 }
 
 /**
- * Show notification in foreground.
+ * Show notification.
  *
  * @return [ BOOL ]
  */
@@ -124,6 +124,16 @@
     return [[dict objectForKey:@"silent"] boolValue];
 }
 
+/**
+ * Show notification in foreground.
+ *
+ * @return [ BOOL ]
+ */
+- (int) priority
+{
+    return [[dict objectForKey:@"priority"] intValue];
+}
+
 /**
  * The badge number for the notification.
  *

+ 9 - 0
www/local-notification-util.js

@@ -33,6 +33,7 @@ exports._defaults = {
     color         : null,
     data          : null,
     defaults      : 0,
+    foreground    : false,
     group         : null,
     groupSummary  : false,
     icon          : null,
@@ -127,6 +128,14 @@ exports.convertProperties = function (options) {
         options.priority = parseToInt('priority', options);
     }
 
+    if (options.foreground === true) {
+        options.priority = Math.max(options.priority, 1);
+    }
+
+    if (options.foreground === false) {
+        options.priority = Math.min(options.priority, 0);
+    }
+
     if (options.defaults) {
         options.defaults = parseToInt('defaults', options);
     }