瀏覽代碼

Move registration for custom dismiss action to UNUserNotificationCenter

Sebastián Katzer 8 年之前
父節點
當前提交
0fe90469fe

+ 2 - 11
src/ios/APPLocalNotification.m

@@ -631,8 +631,7 @@
 
     if ([action isEqualToString:UNNotificationDefaultActionIdentifier]) {
         event = @"click";
-    }
-    
+    } else
     if ([action isEqualToString:UNNotificationDismissActionIdentifier]) {
         event = @"clear";
     }
@@ -655,15 +654,7 @@
     _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]];
+    [_center registerGeneralNotificationCategory];
 }
 
 #pragma mark -

+ 4 - 0
src/ios/UNUserNotificationCenter+APPLocalNotification.h

@@ -25,6 +25,8 @@
 
 @interface UNUserNotificationCenter (APPLocalNotification)
 
+extern NSString * const kAPPGeneralCategory;
+
 typedef NS_ENUM(NSUInteger, APPNotificationType) {
     NotifcationTypeAll = 0,
     NotifcationTypeScheduled = 1,
@@ -36,6 +38,8 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
 @property (readonly, getter=getNotifications) NSArray* localNotifications;
 @property (readonly, getter=getNotificationIds) NSArray* localNotificationIds;
 
+- (void) registerGeneralNotificationCategory;
+
 // List of all notification IDs from given type
 - (NSArray*) getNotificationIdsByType:(APPNotificationType)type;
 

+ 23 - 0
src/ios/UNUserNotificationCenter+APPLocalNotification.m

@@ -26,8 +26,31 @@
 
 @import UserNotifications;
 
+NSString * const kAPPGeneralCategory = @"GENERAL";
+
 @implementation UNUserNotificationCenter (APPLocalNotification)
 
+#pragma mark -
+#pragma mark NotificationCategory
+
+/**
+ * Register general notification category to listen for dismiss actions.
+ *
+ * @return [ Void ]
+ */
+- (void) registerGeneralNotificationCategory
+{
+    UNNotificationCategory* category;
+
+    category = [UNNotificationCategory
+                categoryWithIdentifier:@"GENERAL"
+                actions:@[]
+                intentIdentifiers:@[]
+                options:UNNotificationCategoryOptionCustomDismissAction];
+
+    [self setNotificationCategories:[NSSet setWithObjects:category, nil]];
+}
+
 #pragma mark -
 #pragma mark LocalNotifications