Explorar el Código

Add support for text input actions

Sebastián Katzer hace 8 años
padre
commit
0d85c72cec
Se han modificado 2 ficheros con 29 adiciones y 7 borrados
  1. 2 2
      src/ios/APPLocalNotification.m
  2. 27 5
      src/ios/APPNotificationOptions.m

+ 2 - 2
src/ios/APPLocalNotification.m

@@ -693,12 +693,12 @@
 - (void) fireEvent:(NSString*)event
       notification:(UNNotificationRequest*)request
 {
-    NSString *js, *args;
+    NSString *js;
     NSString *appState = [self applicationState];
     NSString *params   = [NSString stringWithFormat:@"\"%@\"", appState];
 
     if (request) {
-        args   = [request encodeToJSON];
+        NSString *args = [request encodeToJSON];
         params = [NSString stringWithFormat:@"%@,'%@'", args, appState];
     }
 

+ 27 - 5
src/ios/APPNotificationOptions.m

@@ -212,7 +212,10 @@
     for (NSDictionary* item in items) {
         NSString* id    = [item objectForKey:@"id"];
         NSString* title = [item objectForKey:@"title"];
+        NSString* type  = [item objectForKey:@"type"];
+
         UNNotificationActionOptions options = UNNotificationActionOptionNone;
+        UNNotificationAction* action;
         
         if ([[item objectForKey:@"launch"] boolValue]) {
             options = UNNotificationActionOptionForeground;
@@ -226,12 +229,31 @@
             options = options | UNNotificationActionOptionAuthenticationRequired;
         }
         
-        UNNotificationAction* action;
-        action = [UNNotificationAction actionWithIdentifier:id
-                                                      title:title
-                                                    options:options];
+        if ([type isEqualToString:@"input"]) {
+            NSString* submitTitle = [item objectForKey:@"submitTitle"];
+            NSString* placeholder = [item objectForKey:@"emptyText"];
+            
+            if (!submitTitle.length) {
+                submitTitle = @"Submit";
+            }
+            
+            action = [UNTextInputNotificationAction actionWithIdentifier:id
+                                                                   title:title
+                                                                 options:options
+                                                    textInputButtonTitle:submitTitle
+                                                    textInputPlaceholder:placeholder];
+        } else
+        if (!type.length || [type isEqualToString:@"button"]) {
+            action = [UNNotificationAction actionWithIdentifier:id
+                                                          title:title
+                                                        options:options];
+        } else {
+            NSLog(@"Unknown action type: %@", type);
+        }
         
-        [actions addObject:action];
+        if (action) {
+            [actions addObject:action];
+        }
     }
     
     return actions;