react-native-notify-kit 10.1.0 → 10.2.1

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 (52) hide show
  1. package/README.md +99 -96
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/AndroidManifest.xml +0 -1
  4. package/android/src/main/java/app/notifee/core/ForegroundService.java +1 -0
  5. package/android/src/main/java/app/notifee/core/NotificationManager.java +21 -8
  6. package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +16 -0
  7. package/android/src/main/java/app/notifee/core/ReceiverService.java +18 -13
  8. package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +1 -2
  9. package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +3 -9
  10. package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +42 -27
  11. package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +0 -28
  12. package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +79 -41
  13. package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +5 -1
  14. package/android/src/main/kotlin/io/invertase/notifee/NotifeeApiModule.kt +6 -6
  15. package/android/src/main/kotlin/io/invertase/notifee/NotifeeReactUtils.kt +1 -2
  16. package/android/src/test/java/app/notifee/core/model/TimestampTriggerModelTest.java +150 -0
  17. package/cli/dist/lib/patchPodfile.d.ts +3 -1
  18. package/cli/dist/lib/patchPodfile.js +125 -33
  19. package/cli/dist/lib/patchPodfile.js.map +1 -1
  20. package/dist/index.d.ts +2 -0
  21. package/dist/types/Module.d.ts +27 -13
  22. package/dist/types/Notification.d.ts +1 -1
  23. package/dist/types/NotificationIOS.d.ts +44 -21
  24. package/dist/types/NotificationIOS.js +15 -1
  25. package/dist/types/NotificationIOS.js.map +1 -1
  26. package/dist/types/PowerManagerInfo.d.ts +9 -4
  27. package/dist/types/Trigger.d.ts +45 -2
  28. package/dist/types/Trigger.js +22 -0
  29. package/dist/types/Trigger.js.map +1 -1
  30. package/dist/validators/validateIOSCategory.js +2 -2
  31. package/dist/validators/validateIOSCategory.js.map +1 -1
  32. package/dist/validators/validateTrigger.js +26 -1
  33. package/dist/validators/validateTrigger.js.map +1 -1
  34. package/dist/version.d.ts +1 -1
  35. package/dist/version.js +1 -1
  36. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +20 -10
  37. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +1 -2
  38. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +44 -35
  39. package/ios/NotifeeCore/NotifeeCore.m +1042 -119
  40. package/ios/NotifeeCore/NotifeeCoreUtil.h +36 -1
  41. package/ios/NotifeeCore/NotifeeCoreUtil.m +533 -9
  42. package/ios/RNNotifee/NotifeeApiModule.mm +2 -2
  43. package/package.json +1 -1
  44. package/src/index.ts +2 -0
  45. package/src/types/Module.ts +27 -13
  46. package/src/types/Notification.ts +1 -1
  47. package/src/types/NotificationIOS.ts +43 -28
  48. package/src/types/PowerManagerInfo.ts +9 -4
  49. package/src/types/Trigger.ts +45 -1
  50. package/src/validators/validateIOSCategory.ts +4 -2
  51. package/src/validators/validateTrigger.ts +38 -0
  52. package/src/version.ts +1 -1
@@ -17,9 +17,14 @@
17
17
 
18
18
  #import "NotifeeCore+UNUserNotificationCenter.h"
19
19
 
20
+ #import "NotifeeCore.h"
20
21
  #import "NotifeeCoreDelegateHolder.h"
21
22
  #import "NotifeeCoreUtil.h"
22
23
 
24
+ @interface NotifeeCore (RollingTimestampTopUp)
25
+ + (void)topUpRollingTimestampTriggersWithCompletion:(void (^)(NSError *error))completion;
26
+ @end
27
+
23
28
  @implementation NotifeeCoreUNUserNotificationCenter
24
29
 
25
30
  struct {
@@ -63,12 +68,7 @@ struct {
63
68
  });
64
69
  }
65
70
 
66
- - (void)onDidFinishLaunchingNotification:(nonnull NSDictionary *)notifUserInfo {
67
- if (notifUserInfo != nil) {
68
- NSDictionary *notifeeNotification = notifUserInfo[kNotifeeUserInfoNotification];
69
- _initialNoticationID = notifeeNotification[@"id"];
70
- }
71
-
71
+ - (void)markInitialNotificationGathered {
72
72
  _initialNotificationGathered = YES;
73
73
  }
74
74
 
@@ -89,6 +89,24 @@ struct {
89
89
  return nil;
90
90
  }
91
91
 
92
+ - (BOOL)isRollingTimestampNotificationRequest:(UNNotificationRequest *)request {
93
+ if ([NotifeeCoreUtil isRollingInternalNotificationId:request.identifier]) {
94
+ return YES;
95
+ }
96
+
97
+ NSDictionary *trigger = request.content.userInfo[kNotifeeUserInfoTrigger];
98
+ return [NotifeeCoreUtil isRollingTimestampTrigger:trigger];
99
+ }
100
+
101
+ - (void)topUpRollingTimestampTriggersForLifecycleEvent:(NSString *)eventName {
102
+ [NotifeeCore topUpRollingTimestampTriggersWithCompletion:^(NSError *error) {
103
+ if (error != nil) {
104
+ NSLog(@"NotifeeCore: Failed to top up rolling timestamp triggers after %@: %@", eventName,
105
+ error);
106
+ }
107
+ }];
108
+ }
109
+
92
110
  #pragma mark - UNUserNotificationCenter Delegate Methods
93
111
 
94
112
  // The method will be called on the delegate only if the application is in the
@@ -103,6 +121,8 @@ struct {
103
121
  (void (^)(UNNotificationPresentationOptions options))completionHandler {
104
122
  NSDictionary *notifeeNotification =
105
123
  notification.request.content.userInfo[kNotifeeUserInfoNotification];
124
+ BOOL isRollingTimestampNotification =
125
+ [self isRollingTimestampNotificationRequest:notification.request];
106
126
 
107
127
  // we only care about notifications created through notifee
108
128
  if (notifeeNotification != nil) {
@@ -127,25 +147,16 @@ struct {
127
147
  // if list or banner is true, ignore alert property
128
148
  if (banner || list) {
129
149
  if (banner) {
130
- if (@available(iOS 14, *)) {
131
- presentationOptions |= UNNotificationPresentationOptionBanner;
132
- } else {
133
- // for iOS 13 we need to set alert
134
- presentationOptions |= UNNotificationPresentationOptionAlert;
135
- }
150
+ presentationOptions |= UNNotificationPresentationOptionBanner;
136
151
  }
137
152
 
138
153
  if (list) {
139
- if (@available(iOS 14, *)) {
140
- presentationOptions |= UNNotificationPresentationOptionList;
141
- } else {
142
- // for iOS 13 we need to set alert
143
- presentationOptions |= UNNotificationPresentationOptionAlert;
144
- }
154
+ presentationOptions |= UNNotificationPresentationOptionList;
145
155
  }
146
156
  } else if (alert) {
147
157
  // TODO: remove alert once it has been fully removed from the notifee API
148
- presentationOptions |= UNNotificationPresentationOptionAlert;
158
+ presentationOptions |=
159
+ UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionList;
149
160
  }
150
161
 
151
162
  // Emit DELIVERED for every Notifee-owned notification presented in foreground.
@@ -160,6 +171,9 @@ struct {
160
171
  }];
161
172
 
162
173
  completionHandler(presentationOptions);
174
+ if (isRollingTimestampNotification) {
175
+ [self topUpRollingTimestampTriggersForLifecycleEvent:@"foreground delivery"];
176
+ }
163
177
 
164
178
  } else if (_originalDelegate != nil && originalUNCDelegateRespondsTo.willPresentNotification) {
165
179
  [_originalDelegate userNotificationCenter:center
@@ -174,15 +188,9 @@ struct {
174
188
  // @react-native-firebase/messaging). Fall back to the platform default
175
189
  // presentation options instead so the system shows the notification as it
176
190
  // would if Notifee had not installed a delegate at all.
177
- if (@available(iOS 14.0, *)) {
178
- completionHandler(
179
- UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionSound |
180
- UNNotificationPresentationOptionList | UNNotificationPresentationOptionBadge);
181
- } else {
182
- completionHandler(UNNotificationPresentationOptionAlert |
183
- UNNotificationPresentationOptionSound |
184
- UNNotificationPresentationOptionBadge);
185
- }
191
+ completionHandler(UNNotificationPresentationOptionBanner |
192
+ UNNotificationPresentationOptionSound | UNNotificationPresentationOptionList |
193
+ UNNotificationPresentationOptionBadge);
186
194
  }
187
195
  }
188
196
 
@@ -195,6 +203,8 @@ struct {
195
203
  withCompletionHandler:(void (^)(void))completionHandler {
196
204
  NSDictionary *notifeeNotification =
197
205
  response.notification.request.content.userInfo[kNotifeeUserInfoNotification];
206
+ BOOL isRollingTimestampNotification =
207
+ [self isRollingTimestampNotificationRequest:response.notification.request];
198
208
 
199
209
  _notificationOpenedAppID = notifeeNotification[@"id"];
200
210
 
@@ -234,6 +244,9 @@ struct {
234
244
  }
235
245
  }];
236
246
  completionHandler();
247
+ if (isRollingTimestampNotification) {
248
+ [self topUpRollingTimestampTriggersForLifecycleEvent:@"notification response"];
249
+ }
237
250
  return;
238
251
  }
239
252
 
@@ -272,16 +285,12 @@ struct {
272
285
  // store notification for getInitialNotification
273
286
  _initialNotification = [eventDetail copy];
274
287
 
275
- // post PRESS/ACTION_PRESS event
276
- // Set is initial notification to true
277
- if (_notificationOpenedAppID != nil && _initialNoticationID != nil &&
278
- [_initialNoticationID isEqualToString:_notificationOpenedAppID]) {
279
- eventDetail[@"initialNotification"] = @1;
280
- }
281
-
282
288
  [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:event];
283
289
 
284
290
  completionHandler();
291
+ if (isRollingTimestampNotification) {
292
+ [self topUpRollingTimestampTriggersForLifecycleEvent:@"notification response"];
293
+ }
285
294
  } else {
286
295
  // Defensive: parseUNNotificationRequest: currently never returns nil,
287
296
  // but if it did, the completionHandler contract must still be honored.