Преглед на файлове

Proper action identifier handling in delegate

Sebastián Katzer преди 8 години
родител
ревизия
19d5b97a03
променени са 2 файла, в които са добавени 20 реда и са изтрити 8 реда
  1. 19 8
      src/ios/APPLocalNotification.m
  2. 1 0
      src/ios/APPNotificationContent.m

+ 19 - 8
src/ios/APPLocalNotification.m

@@ -626,16 +626,18 @@
           withCompletionHandler:(void (^)())completionHandler
 {
     UNNotificationRequest* notification = response.notification.request;
+    NSString* action = response.actionIdentifier;
+    NSString* event  = action;
 
-    [self fireEvent:@"click" notification:notification];
+    if ([action isEqualToString:UNNotificationDefaultActionIdentifier]) {
+        event = @"click";
+    }
+    
+    if ([action isEqualToString:UNNotificationDismissActionIdentifier]) {
+        event = @"clear";
+    }
 
-//    if ([notification.options isRepeating]) {
-//        [_center clearNotification:notification];
-//        [self fireEvent:@"clear" notification:notification];
-//    } else {
-//        [_center cancelNotification:notification];
-//        [self fireEvent:@"cancel" notification:notification];
-//    }
+    [self fireEvent:event notification:notification];
 
     completionHandler();
 }
@@ -653,6 +655,15 @@
     _center    = [UNUserNotificationCenter currentNotificationCenter];
 
     _center.delegate = self;
+    
+    UNNotificationCategory* generalCategory = [UNNotificationCategory
+                                               categoryWithIdentifier:@"GENERAL"
+                                               actions:@[]
+                                               intentIdentifiers:@[]
+                                               options:UNNotificationCategoryOptionCustomDismissAction];
+    
+    // Register the notification categories.
+    [_center setNotificationCategories:[NSSet setWithObjects:generalCategory, nil]];
 }
 
 #pragma mark -

+ 1 - 0
src/ios/APPNotificationContent.m

@@ -65,6 +65,7 @@ static char optionsKey;
     self.body     = options.text;
     self.sound    = options.sound;
     self.badge    = options.badge;
+    self.categoryIdentifier = @"GENERAL";
 }
 
 #pragma mark -