Przeglądaj źródła

Added silent option for ios

Sebastián Katzer 8 lat temu
rodzic
commit
7022f6af68

+ 5 - 1
src/ios/APPLocalNotification.m

@@ -507,7 +507,11 @@
         [self fireEvent:@"trigger" notification:notification.request];
     }
 
-    completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
+    if (notification.request.options.silent) {
+        completionHandler(UNNotificationPresentationOptionNone);
+    } else {
+        completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
+    }
 }
 
 /**

+ 1 - 0
src/ios/APPNotificationOptions.h

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

+ 10 - 0
src/ios/APPNotificationOptions.m

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

+ 4 - 2
www/local-notification-util.js

@@ -30,8 +30,9 @@ exports._defaults = {
     sound:   'res://platform_default',
     badge:   undefined,
     data:    undefined,
-    trigger: { type: 'calendar' },
+    silent:  false,
     actions: [],
+    trigger: { type: 'calendar' },
     actionGroupId: undefined,
     attachments: []
 };
@@ -201,7 +202,8 @@ exports.convertTrigger = function (options) {
     var isCal = trigger.type == 'calendar';
 
     if (isCal && !date) {
-        date = this.getValueFor(options, 'trigger', 'at', 'firstAt', 'date');
+        date = this.getValueFor(options, 'at', 'firstAt', 'date');
+        date = date || isObject && !cfg.getTime ? new Date() : options.trigger;
         date = date || new Date();
     }