cordova-plugin-local-notifications-continued 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/.github/ISSUE_TEMPLATE/report_issue.yml +126 -0
  3. package/CHANGELOG.md +358 -0
  4. package/LICENSE +202 -0
  5. package/README.md +1531 -0
  6. package/images/android-actions-with-input-clicked.png +0 -0
  7. package/images/android-actions-with-input-not-clicked.png +0 -0
  8. package/images/android-actions.png +0 -0
  9. package/images/android-alarms-and-reminders-in-app-settings.png +0 -0
  10. package/images/android-alarms-and-reminders-setting.png +0 -0
  11. package/images/android-app-hibernation-notification.png +0 -0
  12. package/images/android-app-hibernation-settings-android-12.png +0 -0
  13. package/images/android-app-hibernation-settings-android-13-14.png +0 -0
  14. package/images/android-app-hibernation-settings-android-15.png +0 -0
  15. package/images/android-attachments-image-folded.png +0 -0
  16. package/images/android-attachments-image-unfolded.png +0 -0
  17. package/images/android-chat.png +0 -0
  18. package/images/android-icon.svg +19 -0
  19. package/images/android-inbox.png +0 -0
  20. package/images/android-notification-example.png +0 -0
  21. package/images/android-progress.png +0 -0
  22. package/images/android-request-permission.png +0 -0
  23. package/images/android-stack.png +0 -0
  24. package/images/apple-icon.svg +1 -0
  25. package/images/cordova-app-notified-logo.png +0 -0
  26. package/images/ios-actions-with-input.png +0 -0
  27. package/images/ios-actions.png +0 -0
  28. package/images/ios-attachments-image-folded.png +0 -0
  29. package/images/ios-attachments-image-unfolded.png +0 -0
  30. package/images/ios-notification.png +0 -0
  31. package/images/ios-request-permission.png +0 -0
  32. package/images/logo.png +0 -0
  33. package/package.json +53 -0
  34. package/plugin.xml +266 -0
  35. package/src/android/ClickActivity.java +72 -0
  36. package/src/android/LocalNotification.java +779 -0
  37. package/src/android/Manager.java +327 -0
  38. package/src/android/Notification.java +844 -0
  39. package/src/android/Options.java +956 -0
  40. package/src/android/OptionsTrigger.java +104 -0
  41. package/src/android/action/Action.java +214 -0
  42. package/src/android/action/ActionGroup.java +135 -0
  43. package/src/android/build/localnotification.gradle +29 -0
  44. package/src/android/receiver/ClearReceiver.java +61 -0
  45. package/src/android/receiver/RestoreReceiver.java +70 -0
  46. package/src/android/receiver/TriggerReceiver.java +70 -0
  47. package/src/android/trigger/TriggerHandler.java +195 -0
  48. package/src/android/trigger/TriggerHandlerAt.java +63 -0
  49. package/src/android/trigger/TriggerHandlerEvery.java +257 -0
  50. package/src/android/trigger/TriggerHandlerIn.java +69 -0
  51. package/src/android/util/AssetUtil.java +385 -0
  52. package/src/android/util/CallbackContextUtil.java +88 -0
  53. package/src/android/util/PluginFileProvider.java +34 -0
  54. package/src/android/xml/shared_files_provider_paths.xml +38 -0
  55. package/src/ios/APPLocalNotification.h +56 -0
  56. package/src/ios/APPLocalNotification.m +650 -0
  57. package/src/ios/APPNotificationCategory.h +28 -0
  58. package/src/ios/APPNotificationCategory.m +107 -0
  59. package/src/ios/APPNotificationContent.h +32 -0
  60. package/src/ios/APPNotificationContent.m +122 -0
  61. package/src/ios/APPNotificationOptions.h +42 -0
  62. package/src/ios/APPNotificationOptions.m +689 -0
  63. package/src/ios/UNNotificationRequest+APPLocalNotification.h +32 -0
  64. package/src/ios/UNNotificationRequest+APPLocalNotification.m +100 -0
  65. package/src/ios/UNUserNotificationCenter+APPLocalNotification.h +60 -0
  66. package/src/ios/UNUserNotificationCenter+APPLocalNotification.m +344 -0
  67. package/www/local-notification.js +1104 -0
@@ -0,0 +1,650 @@
1
+ /*
2
+ * Apache 2.0 License
3
+ *
4
+ * Copyright (c) Sebastian Katzer 2017
5
+ *
6
+ * This file contains Original Code and/or Modifications of Original Code
7
+ * as defined in and that are subject to the Apache License
8
+ * Version 2.0 (the 'License'). You may not use this file except in
9
+ * compliance with the License. Please obtain a copy of the License at
10
+ * http://opensource.org/licenses/Apache-2.0/ and read it before using this
11
+ * file.
12
+ *
13
+ * The Original Code and all software distributed under the License are
14
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18
+ * Please see the License for the specific language governing rights and
19
+ * limitations under the License.
20
+ */
21
+
22
+ // codebeat:disable[TOO_MANY_FUNCTIONS]
23
+
24
+ #import "APPLocalNotification.h"
25
+ #import "APPNotificationContent.h"
26
+ #import "APPNotificationOptions.h"
27
+ #import "APPNotificationCategory.h"
28
+ #import "UNUserNotificationCenter+APPLocalNotification.h"
29
+ #import "UNNotificationRequest+APPLocalNotification.h"
30
+
31
+ @interface APPLocalNotification ()
32
+
33
+ @property (strong, nonatomic) UNUserNotificationCenter* center;
34
+ @property (NS_NONATOMIC_IOSONLY, nullable, weak) id <UNUserNotificationCenterDelegate> delegate;
35
+ @property (readwrite, assign) BOOL deviceready;
36
+ @property (readwrite, assign) BOOL isActive;
37
+ @property (readonly, nonatomic, retain) NSArray* launchDetails;
38
+ @property (readonly, nonatomic, retain) NSMutableArray* eventQueue;
39
+
40
+ @end
41
+
42
+ @implementation APPLocalNotification
43
+
44
+ @synthesize deviceready, isActive, eventQueue;
45
+
46
+ #pragma mark -
47
+ #pragma mark Life Cycle
48
+
49
+ /**
50
+ * Registers obervers after plugin was initialized.
51
+ */
52
+ - (void) pluginInitialize
53
+ {
54
+ NSLog(@"LocalNotification: pluginInitialize");
55
+ eventQueue = [[NSMutableArray alloc] init];
56
+ _center = [UNUserNotificationCenter currentNotificationCenter];
57
+ _delegate = _center.delegate;
58
+
59
+ _center.delegate = self;
60
+ [_center registerGeneralNotificationCategory];
61
+
62
+ [self monitorAppStateChanges];
63
+ }
64
+
65
+ /**
66
+ * Monitor changes of the app state and update the _isActive flag.
67
+ */
68
+ - (void) monitorAppStateChanges
69
+ {
70
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
71
+
72
+ [center addObserverForName:UIApplicationDidBecomeActiveNotification
73
+ object:NULL queue:[NSOperationQueue mainQueue]
74
+ usingBlock:^(NSNotification *e) { self->isActive = YES; }];
75
+
76
+ [center addObserverForName:UIApplicationDidEnterBackgroundNotification
77
+ object:NULL queue:[NSOperationQueue mainQueue]
78
+ usingBlock:^(NSNotification *e) { self->isActive = NO; }];
79
+ }
80
+
81
+ #pragma mark -
82
+ #pragma mark Interface
83
+
84
+
85
+ /**
86
+ * Set launchDetails object.
87
+ */
88
+ - (void) launch:(CDVInvokedUrlCommand*)command
89
+ {
90
+ if (!_launchDetails) return;
91
+
92
+ [self.commandDelegate evalJs:[NSString
93
+ stringWithFormat:@"cordova.plugins.notification.local.launchDetails = {id:%@, action:'%@'}",
94
+ _launchDetails[0], _launchDetails[1]]];
95
+
96
+ _launchDetails = NULL;
97
+ }
98
+
99
+ /**
100
+ * Execute all queued events.
101
+ */
102
+ - (void) ready:(CDVInvokedUrlCommand*)command
103
+ {
104
+ deviceready = YES;
105
+
106
+ [self.commandDelegate runInBackground:^{
107
+ for (NSString* js in self->eventQueue) {
108
+ [self.commandDelegate evalJs:js];
109
+ }
110
+ [self->eventQueue removeAllObjects];
111
+ }];
112
+ }
113
+
114
+ /**
115
+ * Schedule notifications.
116
+ */
117
+ - (void) schedule:(CDVInvokedUrlCommand*)command
118
+ {
119
+ [self.commandDelegate runInBackground:^{
120
+ for (NSDictionary* options in command.arguments) {
121
+ [self scheduleNotification:[[APPNotificationContent alloc] initWithOptions:options]];
122
+ }
123
+
124
+ [self hasPermission:command];
125
+ }];
126
+ }
127
+
128
+ /**
129
+ * Update notifications.
130
+ */
131
+ - (void) update:(CDVInvokedUrlCommand*)command
132
+ {
133
+ NSArray* notifications = command.arguments;
134
+
135
+ [self.commandDelegate runInBackground:^{
136
+ for (NSDictionary* options in notifications) {
137
+ NSNumber* id = [options objectForKey:@"id"];
138
+ UNNotificationRequest* notification;
139
+
140
+ notification = [self->_center getNotificationWithId:id];
141
+
142
+ if (!notification)
143
+ continue;
144
+
145
+ [self updateNotification:[notification copy]
146
+ withOptions:options];
147
+
148
+ [self fireEvent:@"update" notification:notification];
149
+ }
150
+
151
+ [self hasPermission:command];
152
+ }];
153
+ }
154
+
155
+ /**
156
+ * Clear notifications by id.
157
+ * @param command Contains the IDs of the notifications to clear.
158
+ */
159
+ - (void) clear:(CDVInvokedUrlCommand*)command
160
+ {
161
+ [self.commandDelegate runInBackground:^{
162
+ for (NSNumber* id in command.arguments) {
163
+ UNNotificationRequest* notification = [self->_center getNotificationWithId:id];
164
+ if (!notification) continue;
165
+ [self->_center clearNotification:notification];
166
+ [self fireEvent:@"clear" notification:notification];
167
+ }
168
+
169
+ [self execCallback:command];
170
+ }];
171
+ }
172
+
173
+ /**
174
+ * Clear all local notifications.
175
+ */
176
+ - (void) clearAll:(CDVInvokedUrlCommand*)command
177
+ {
178
+ [self.commandDelegate runInBackground:^{
179
+ [self->_center clearNotifications];
180
+ [self clearApplicationIconBadgeNumber];
181
+ [self fireEvent:@"clearall"];
182
+ [self execCallback:command];
183
+ }];
184
+ }
185
+
186
+ /**
187
+ * Cancel notifications by id.
188
+ * @param command Contains the IDs of the notifications to clear.
189
+ */
190
+ - (void) cancel:(CDVInvokedUrlCommand*)command
191
+ {
192
+ [self.commandDelegate runInBackground:^{
193
+ for (NSNumber* id in command.arguments) {
194
+ UNNotificationRequest* notification = [self->_center getNotificationWithId:id];
195
+ if (!notification) continue;
196
+ [self->_center cancelNotification:notification];
197
+ [self fireEvent:@"cancel" notification:notification];
198
+ }
199
+
200
+ [self execCallback:command];
201
+ }];
202
+ }
203
+
204
+ /**
205
+ * Cancel all local notifications.
206
+ */
207
+ - (void) cancelAll:(CDVInvokedUrlCommand*)command
208
+ {
209
+ [self.commandDelegate runInBackground:^{
210
+ [self->_center cancelNotifications];
211
+ [self clearApplicationIconBadgeNumber];
212
+ [self fireEvent:@"cancelall"];
213
+ [self execCallback:command];
214
+ }];
215
+ }
216
+
217
+ /**
218
+ * Get type of notification.
219
+ * @param command Contains the type to check.
220
+ */
221
+ - (void) type:(CDVInvokedUrlCommand*)command
222
+ {
223
+ [self.commandDelegate runInBackground:^{
224
+ NSString* type;
225
+
226
+ switch ([self->_center getTypeOfNotificationWithId:[command argumentAtIndex:0]]) {
227
+ case NotifcationTypeScheduled:
228
+ type = @"scheduled";
229
+ break;
230
+ case NotifcationTypeTriggered:
231
+ type = @"triggered";
232
+ break;
233
+ default:
234
+ type = @"unknown";
235
+ }
236
+
237
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
238
+ messageAsString:type]
239
+ callbackId:command.callbackId];
240
+ }];
241
+ }
242
+
243
+ /**
244
+ * List of notification IDs by type.
245
+ */
246
+ - (void) ids:(CDVInvokedUrlCommand*)command
247
+ {
248
+ [self.commandDelegate runInBackground:^{
249
+ APPNotificationType type = NotifcationTypeUnknown;
250
+
251
+ switch ([command.arguments[0] intValue]) {
252
+ case 0:
253
+ type = NotifcationTypeAll;
254
+ break;
255
+ case 1:
256
+ type = NotifcationTypeScheduled;
257
+ break;
258
+ case 2:
259
+ type = NotifcationTypeTriggered;
260
+ break;
261
+ }
262
+
263
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
264
+ messageAsArray:[self->_center getNotificationIdsByType:type]]
265
+ callbackId:command.callbackId];
266
+ }];
267
+ }
268
+
269
+ /**
270
+ * Notification by id.
271
+ * @param command Contains the id of the notification to return.
272
+ */
273
+ - (void) notification:(CDVInvokedUrlCommand*)command
274
+ {
275
+ [self.commandDelegate runInBackground:^{
276
+ // command.arguments is a list of ids
277
+ NSArray* notifications = [self->_center getNotificationOptionsById:command.arguments];
278
+
279
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
280
+ messageAsDictionary:[notifications firstObject]]
281
+ callbackId:command.callbackId];
282
+ }];
283
+ }
284
+
285
+ /**
286
+ * Get notifications by type or ids.
287
+ * @param command Contains the ids of the notifications to return.
288
+ */
289
+ - (void) notifications:(CDVInvokedUrlCommand*)command
290
+ {
291
+ [self.commandDelegate runInBackground:^{
292
+ APPNotificationType type = NotifcationTypeUnknown;
293
+ NSArray* notifications;
294
+
295
+ switch ([command.arguments[0] intValue]) {
296
+ case 0:
297
+ type = NotifcationTypeAll;
298
+ break;
299
+ case 1:
300
+ type = NotifcationTypeScheduled;
301
+ break;
302
+ case 2:
303
+ type = NotifcationTypeTriggered;
304
+ break;
305
+
306
+ // Get notifications by ids
307
+ case 3:
308
+ notifications = [self->_center getNotificationOptionsById:command.arguments[1]];
309
+ break;
310
+ }
311
+
312
+ // Get notifications by type
313
+ if (notifications == nil) {
314
+ notifications = [self->_center getNotificationOptionsByType:type];
315
+ }
316
+
317
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
318
+ messageAsArray:notifications]
319
+ callbackId:command.callbackId];
320
+ }];
321
+ }
322
+
323
+ /**
324
+ * Check for permission to show notifications.
325
+ */
326
+ - (void) hasPermission:(CDVInvokedUrlCommand*)command
327
+ {
328
+ [_center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings* settings) {
329
+ BOOL authorized = settings.authorizationStatus == UNAuthorizationStatusAuthorized;
330
+ BOOL enabled = settings.notificationCenterSetting == UNNotificationSettingEnabled;
331
+ [self execCallback:command arg:authorized && enabled];
332
+ }];
333
+ }
334
+
335
+ /**
336
+ * Request for permission to show notifcations.
337
+ */
338
+ - (void) requestPermission:(CDVInvokedUrlCommand*)command
339
+ {
340
+ [_center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
341
+ completionHandler:^(BOOL granted, NSError* e) {
342
+ [self hasPermission:command];
343
+ }
344
+ ];
345
+ }
346
+
347
+ /**
348
+ * Register, removes or checks for an action group.
349
+ */
350
+ - (void) actions:(CDVInvokedUrlCommand *)command
351
+ {
352
+ [self.commandDelegate runInBackground:^{
353
+ NSString* actionGroupId = [command argumentAtIndex:1];
354
+
355
+ // The first agrument defines, which method was called
356
+ switch ([command.arguments[0] intValue]) {
357
+ // addActions was called
358
+ case 0: {
359
+ NSArray* actions = [command argumentAtIndex:2];
360
+ [self->_center addActionGroup:[APPNotificationCategory parse:actions
361
+ withId:actionGroupId]];
362
+ [self execCallback:command];
363
+ break;
364
+ }
365
+ // removeActions was called
366
+ case 1:
367
+ [self->_center removeActionGroup:actionGroupId];
368
+ [self execCallback:command];
369
+ break;
370
+ // hasActions was called
371
+ case 2:
372
+ [self execCallback:command arg:[self->_center hasActionGroup:actionGroupId]];
373
+ break;
374
+ }
375
+ }];
376
+ }
377
+
378
+ /**
379
+ * Open native settings to enable notifications.
380
+ * In iOS it's not possible to open the notification settings, only the app settings.
381
+ */
382
+ - (void) openNotificationSettings:(CDVInvokedUrlCommand*)command
383
+ {
384
+ @try {
385
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
386
+ options:@{}
387
+ completionHandler:^(BOOL success) {
388
+ if (success) {
389
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
390
+ callbackId:command.callbackId];
391
+ } else {
392
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]
393
+ callbackId:command.callbackId];
394
+ }
395
+ }];
396
+ }
397
+ @catch (NSException *exception) {
398
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
399
+ messageAsString:exception.reason]
400
+ callbackId:command.callbackId];
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Clear the badge number on the app icon. Called from JavaScript.
406
+ */
407
+ - (void) clearBadge:(CDVInvokedUrlCommand*)command
408
+ {
409
+ [self clearApplicationIconBadgeNumber];
410
+ [self execCallback:command];
411
+ }
412
+
413
+ #pragma mark -
414
+ #pragma mark Private
415
+
416
+ /**
417
+ * Schedule the local notification.
418
+ */
419
+ - (void) scheduleNotification:(APPNotificationContent*)appNotificationContent
420
+ {
421
+ __weak APPLocalNotification* weakSelf = self;
422
+ UNNotificationRequest* request = appNotificationContent.request;
423
+ NSString* event = [request wasUpdated] ? @"update" : @"add";
424
+
425
+ NSLog(@"Schedule notification, event=%@, trigger=%@, options=%@", event, request.trigger, appNotificationContent.options);
426
+
427
+ [_center addNotificationRequest:request
428
+ withCompletionHandler:^(NSError* e) {
429
+ __strong APPLocalNotification* strongSelf = weakSelf;
430
+ [strongSelf fireEvent:event notification:request];
431
+ }
432
+ ];
433
+ }
434
+
435
+ /**
436
+ * Update the local notification.
437
+ * @param notification The notification to update.
438
+ * @param newOptions The options to update.
439
+ */
440
+ - (void) updateNotification:(UNNotificationRequest*)notification
441
+ withOptions:(NSDictionary*)newOptions
442
+ {
443
+ NSMutableDictionary* options = [notification.content.userInfo mutableCopy];
444
+
445
+ [options addEntriesFromDictionary:newOptions];
446
+ [options setObject:[NSDate date] forKey:@"updatedAt"];
447
+
448
+ [self scheduleNotification:[[APPNotificationContent alloc] initWithOptions:options]];
449
+ }
450
+
451
+ #pragma mark -
452
+ #pragma mark UNUserNotificationCenterDelegate
453
+
454
+ /**
455
+ * The method will be called on the delegate only if the application is in the foreground.
456
+ */
457
+ - (void) userNotificationCenter:(UNUserNotificationCenter *)center
458
+ willPresentNotification:(UNNotification *)notification
459
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
460
+ {
461
+ [_delegate userNotificationCenter:center
462
+ willPresentNotification:notification
463
+ withCompletionHandler:completionHandler];
464
+
465
+ if ([notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]) return;
466
+
467
+ APPNotificationOptions* notificationOptions = notification.request.options;
468
+ NSLog(@"Handle notification while app is in foreground: %@", notificationOptions);
469
+
470
+ if (![notification.request wasUpdated]) {
471
+ [self fireEvent:@"trigger" notification:notification.request];
472
+ }
473
+
474
+ // Init to None, if notification should be silent
475
+ UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionNone;
476
+
477
+ // Notification should not be silent
478
+ if (!notificationOptions.silent) {
479
+ // Default is badge, sound and notification center like in Android
480
+ presentationOptions = UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound;
481
+
482
+ // Display notification always in Notification Center like in Android
483
+ // Only works since iOS 14, UNNotificationPresentationOptionAlert was splitted in
484
+ // UNNotificationPresentationOptionList and UNNotificationPresentationOptionBanner
485
+ if (@available(iOS 14, *)) {
486
+ presentationOptions |= UNNotificationPresentationOptionList;
487
+ }
488
+
489
+ // Show banner only when option iOSForeground is true, or app is in background
490
+ if (notificationOptions.iOSForeground || !isActive) {
491
+ // UNNotificationPresentationOptionBanner available since iOS 14
492
+ if (@available(iOS 14, *)) {
493
+ presentationOptions |= UNNotificationPresentationOptionBanner;
494
+
495
+ // iOS older then 14: Show notification as banner and in notification center
496
+ } else {
497
+ #pragma clang diagnostic push
498
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
499
+ presentationOptions |= UNNotificationPresentationOptionAlert;
500
+ #pragma clang diagnostic pop
501
+ }
502
+ }
503
+ }
504
+
505
+ completionHandler(presentationOptions);
506
+ }
507
+
508
+ /**
509
+ * Called to let your app know which action was selected by the user for a given
510
+ * notification.
511
+ */
512
+ - (void) userNotificationCenter:(UNUserNotificationCenter *)center
513
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
514
+ withCompletionHandler:(void (^)(void))handler
515
+ {
516
+ UNNotificationRequest* toast = response.notification.request;
517
+
518
+ [_delegate userNotificationCenter:center
519
+ didReceiveNotificationResponse:response
520
+ withCompletionHandler:handler];
521
+
522
+ handler();
523
+
524
+ if ([toast.trigger isKindOfClass:UNPushNotificationTrigger.class]) return;
525
+
526
+ NSString* action = response.actionIdentifier;
527
+ NSString* event = action;
528
+
529
+ if ([action isEqualToString:UNNotificationDefaultActionIdentifier]) {
530
+ event = @"click";
531
+ } else
532
+ if ([action isEqualToString:UNNotificationDismissActionIdentifier]) {
533
+ event = @"clear";
534
+ }
535
+
536
+ if (!deviceready && [event isEqualToString:@"click"]) {
537
+ _launchDetails = @[toast.options.id, event];
538
+ }
539
+
540
+ if (![event isEqualToString:@"clear"]) {
541
+ [self fireEvent:@"clear" notification:toast];
542
+ }
543
+
544
+ NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
545
+
546
+ if ([response isKindOfClass:UNTextInputNotificationResponse.class]) {
547
+ [data setObject:((UNTextInputNotificationResponse*) response).userText
548
+ forKey:@"text"];
549
+ }
550
+
551
+ [self fireEvent:event notification:toast data:data];
552
+ }
553
+
554
+ #pragma mark -
555
+ #pragma mark Helper
556
+
557
+ /**
558
+ * Removes the badge number from the app icon.
559
+ */
560
+ - (void) clearApplicationIconBadgeNumber
561
+ {
562
+ NSLog(@"LocalNotification: clear application badge");
563
+ dispatch_async(dispatch_get_main_queue(), ^{
564
+ [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
565
+ });
566
+ }
567
+
568
+ /**
569
+ * Invokes the callback without any parameter.
570
+ */
571
+ - (void) execCallback:(CDVInvokedUrlCommand*)command
572
+ {
573
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
574
+ callbackId:command.callbackId];
575
+ }
576
+
577
+ /**
578
+ * Invokes the callback with a single boolean parameter.
579
+ */
580
+ - (void) execCallback:(CDVInvokedUrlCommand*)command arg:(BOOL)arg
581
+ {
582
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
583
+ messageAsBool:arg]
584
+ callbackId:command.callbackId];
585
+ }
586
+
587
+ /**
588
+ * Fire general event.
589
+ * @param event The name of the event to fire.
590
+ */
591
+ - (void) fireEvent:(NSString*)event
592
+ {
593
+ [self fireEvent:event notification:NULL data:[[NSMutableDictionary alloc] init]];
594
+ }
595
+
596
+ /**
597
+ * Fire event for about a local notification.
598
+ * @param event The name of the event to fire.
599
+ * @param notificationRequest The UNNotificationRequest
600
+ */
601
+ - (void) fireEvent:(NSString*)event
602
+ notification:(UNNotificationRequest*)notificationRequest
603
+ {
604
+ [self fireEvent:event notification:notificationRequest data:[[NSMutableDictionary alloc] init]];
605
+ }
606
+
607
+ /**
608
+ * Fire event for about a local notification.
609
+ * @param event The name of the event to fire.
610
+ * @param notificationRequest The UNNotificationRequest
611
+ * @param data Event object with additional data.
612
+ */
613
+ - (void) fireEvent:(NSString*)event
614
+ notification:(UNNotificationRequest*)notificationRequest
615
+ data:(NSMutableDictionary*)data
616
+ {
617
+ [data setObject:event forKey:@"event"];
618
+ [data setObject:@(isActive) forKey:@"foreground"];
619
+ [data setObject:@(!deviceready) forKey:@"queued"];
620
+
621
+ if (notificationRequest) {
622
+ [data setObject:notificationRequest.options.id forKey:@"notification"];
623
+ }
624
+
625
+ NSString *params;
626
+ NSString *dataAsJSON = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data
627
+ options:0
628
+ error:NULL]
629
+ encoding:NSUTF8StringEncoding];
630
+
631
+ if (notificationRequest) {
632
+ params = [NSString stringWithFormat:@"%@,%@", [notificationRequest encodeToJSON], dataAsJSON];
633
+ } else {
634
+ params = [NSString stringWithFormat:@"%@", dataAsJSON];
635
+ }
636
+
637
+ NSString *js = [NSString stringWithFormat:@"cordova.plugins.notification.local.fireEvent('%@', %@)", event, params];
638
+
639
+ NSLog(@"%@", js);
640
+
641
+ if (deviceready) {
642
+ [self.commandDelegate evalJs:js];
643
+ } else {
644
+ [self.eventQueue addObject:js];
645
+ }
646
+ }
647
+
648
+ @end
649
+
650
+ // codebeat:enable[TOO_MANY_FUNCTIONS]
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Apache 2.0 License
3
+ *
4
+ * Copyright (c) Sebastian Katzer 2017
5
+ *
6
+ * This file contains Original Code and/or Modifications of Original Code
7
+ * as defined in and that are subject to the Apache License
8
+ * Version 2.0 (the 'License'). You may not use this file except in
9
+ * compliance with the License. Please obtain a copy of the License at
10
+ * http://opensource.org/licenses/Apache-2.0/ and read it before using this
11
+ * file.
12
+ *
13
+ * The Original Code and all software distributed under the License are
14
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18
+ * Please see the License for the specific language governing rights and
19
+ * limitations under the License.
20
+ */
21
+
22
+ @import UserNotifications;
23
+
24
+ @interface APPNotificationCategory : NSObject
25
+
26
+ + (UNNotificationCategory*) parse:(NSArray*)list withId:(NSString*)groupId;
27
+
28
+ @end