react-native-macos 0.73.4 → 0.73.5

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.
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 73,
15
- patch: 4,
15
+ patch: 5,
16
16
  prerelease: null,
17
17
  };
@@ -20,17 +20,45 @@ type Permissions = {|
20
20
 
21
21
  type Notification = {|
22
22
  +alertTitle?: ?string,
23
- // Actual type: string | number
24
- +fireDate?: ?number,
25
23
  +alertBody?: ?string,
26
- +alertAction?: ?string,
27
24
  +userInfo?: ?Object,
25
+ /**
26
+ * Identifier for the notification category. See the [Apple documentation](https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types)
27
+ * for more details.
28
+ */
28
29
  +category?: ?string,
29
- // Actual type: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute'
30
- +repeatInterval?: ?string,
30
+ /**
31
+ * Actual type: string | number
32
+ *
33
+ * Schedule notifications using EITHER `fireDate` or `fireIntervalSeconds`.
34
+ * If both are specified, `fireDate` takes precedence.
35
+ * If you use `presentLocalNotification`, both will be ignored
36
+ * and the notification will be shown immediately.
37
+ */
38
+ +fireDate?: ?number,
39
+ /**
40
+ * Seconds from now to display the notification.
41
+ *
42
+ * Schedule notifications using EITHER `fireDate` or `fireIntervalSeconds`.
43
+ * If both are specified, `fireDate` takes precedence.
44
+ * If you use `presentLocalNotification`, both will be ignored
45
+ * and the notification will be shown immediately.
46
+ */
47
+ +fireIntervalSeconds?: ?number,
48
+ /** Badge count to display on the app icon. */
31
49
  +applicationIconBadgeNumber?: ?number,
50
+ /** Whether to silence the notification sound. */
32
51
  +isSilent?: ?boolean,
52
+ /**
53
+ * Custom notification sound to play. Write-only: soundName will be null when
54
+ * accessing already created notifications using getScheduledLocalNotifications
55
+ * or getDeliveredNotifications.
56
+ */
33
57
  +soundName?: ?string,
58
+ /** DEPRECATED. This was used for iOS's legacy UILocalNotification. */
59
+ +alertAction?: ?string,
60
+ /** DEPRECATED. Use `fireDate` or `fireIntervalSeconds` instead. */
61
+ +repeatInterval?: ?string,
34
62
  |};
35
63
 
36
64
  export interface Spec extends TurboModule {
@@ -16,9 +16,6 @@ typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
16
16
  #endif // [macOS]
17
17
 
18
18
  #if !TARGET_OS_UIKITFORMAC
19
- #if !TARGET_OS_OSX // [macOS]
20
- + (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
21
- #endif // [macOS]
22
19
  + (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
23
20
  + (void)didReceiveRemoteNotification:(NSDictionary *)notification;
24
21
  #if !TARGET_OS_OSX // [macOS]
@@ -25,88 +25,66 @@ static NSString *const kRemoteNotificationRegistrationFailed = @"RemoteNotificat
25
25
  static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";
26
26
 
27
27
  #if !TARGET_OS_UIKITFORMAC
28
- @implementation RCTConvert (NSCalendarUnit)
29
-
30
- RCT_ENUM_CONVERTER(
31
- NSCalendarUnit,
32
- (@{
33
- @"year" : @(NSCalendarUnitYear),
34
- @"month" : @(NSCalendarUnitMonth),
35
- @"week" : @(NSCalendarUnitWeekOfYear),
36
- @"day" : @(NSCalendarUnitDay),
37
- @"hour" : @(NSCalendarUnitHour),
38
- @"minute" : @(NSCalendarUnitMinute)
39
- }),
40
- 0,
41
- integerValue)
42
-
43
- @end
44
28
 
45
29
  @interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
46
30
  @property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks;
47
31
  @end
48
32
 
49
- @implementation RCTConvert (UILocalNotification)
33
+ @implementation RCTConvert (UNNotificationContent)
50
34
 
51
- #if !TARGET_OS_OSX // [macOS]
52
- + (UILocalNotification *)UILocalNotification:(id)json
35
+ + (UNNotificationContent *)UNNotificationContent:(id)json
53
36
  {
54
37
  NSDictionary<NSString *, id> *details = [self NSDictionary:json];
55
38
  BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
56
- UILocalNotification *notification = [UILocalNotification new];
57
- notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
58
- notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
59
- notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
60
- notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
61
- notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
62
- notification.category = [RCTConvert NSString:details[@"category"]];
63
- notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
39
+ UNMutableNotificationContent *content = [UNMutableNotificationContent new];
40
+ content.title = [RCTConvert NSString:details[@"alertTitle"]];
41
+ content.body = [RCTConvert NSString:details[@"alertBody"]];
42
+ content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
43
+ content.categoryIdentifier = [RCTConvert NSString:details[@"category"]];
64
44
  if (details[@"applicationIconBadgeNumber"]) {
65
- notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]];
45
+ content.badge = [RCTConvert NSNumber:details[@"applicationIconBadgeNumber"]];
66
46
  }
67
47
  if (!isSilent) {
68
- notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
48
+ NSString *soundName = [RCTConvert NSString:details[@"soundName"]];
49
+ content.sound =
50
+ soundName ? [UNNotificationSound soundNamed:details[@"soundName"]] : [UNNotificationSound defaultSound];
69
51
  }
70
- return notification;
52
+
53
+ return content;
71
54
  }
72
- #else // [macOS
73
- + (NSUserNotification *)NSUserNotification:(id)json
55
+
56
+ + (NSDictionary<NSString *, id> *)NSDictionaryForNotification:
57
+ (JS::NativePushNotificationManagerIOS::Notification &)notification
74
58
  {
75
- NSDictionary<NSString *, id> *details = [self NSDictionary:json];
76
- BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
77
- NSUserNotification *notification = [NSUserNotification new];
78
- notification.deliveryDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
79
- notification.informativeText = [RCTConvert NSString:details[@"alertBody"]];
80
- NSString *title = [RCTConvert NSString:details[@"alertTitle"]];
81
- if (title) {
82
- notification.title = title;
83
- }
84
- NSString *actionButtonTitle = [RCTConvert NSString:details[@"alertAction"]];
85
- if (actionButtonTitle) {
86
- notification.actionButtonTitle = actionButtonTitle;
59
+ // Note: alertAction is not set, as it is no longer relevant with UNNotification
60
+ NSMutableDictionary *notificationDict = [NSMutableDictionary new];
61
+ notificationDict[@"alertTitle"] = notification.alertTitle();
62
+ notificationDict[@"alertBody"] = notification.alertBody();
63
+ notificationDict[@"userInfo"] = notification.userInfo();
64
+ notificationDict[@"category"] = notification.category();
65
+ if (notification.fireIntervalSeconds()) {
66
+ notificationDict[@"fireIntervalSeconds"] = @(*notification.fireIntervalSeconds());
87
67
  }
88
- notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
89
-
90
- NSCalendarUnit calendarUnit = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
91
- if (calendarUnit > 0) {
92
- NSDateComponents *dateComponents = [NSDateComponents new];
93
- [dateComponents setValue:1 forComponent:calendarUnit];
94
- notification.deliveryRepeatInterval = dateComponents;
68
+ if (notification.fireDate()) {
69
+ notificationDict[@"fireDate"] = @(*notification.fireDate());
95
70
  }
96
- if (!isSilent) {
97
- notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: NSUserNotificationDefaultSoundName;
71
+ if (notification.applicationIconBadgeNumber()) {
72
+ notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
98
73
  }
99
-
100
- NSString *identifier = [RCTConvert NSString:details[@"identifier"]];
101
- if (identifier == nil) {
102
- identifier = [[NSUUID UUID] UUIDString];
74
+ if (notification.isSilent()) {
75
+ notificationDict[@"isSilent"] = @(*notification.isSilent());
76
+ if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) {
77
+ notificationDict[@"soundName"] = notification.soundName();
78
+ }
103
79
  }
104
- notification.identifier = identifier;
105
- return notification;
80
+ return notificationDict;
106
81
  }
107
- #endif // macOS]
82
+
83
+ @end
108
84
 
109
85
  #if !TARGET_OS_OSX // [macOS]
86
+ @implementation RCTConvert (UIBackgroundFetchResult)
87
+
110
88
  RCT_ENUM_CONVERTER(
111
89
  UIBackgroundFetchResult,
112
90
  (@{
@@ -116,9 +94,9 @@ RCT_ENUM_CONVERTER(
116
94
  }),
117
95
  UIBackgroundFetchResultNoData,
118
96
  integerValue)
119
- #endif // [macOS]
120
97
 
121
98
  @end
99
+ #endif // [macOS]
122
100
  #else
123
101
  @interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
124
102
  @end
@@ -126,8 +104,10 @@ RCT_ENUM_CONVERTER(
126
104
 
127
105
  @implementation RCTPushNotificationManager
128
106
 
129
- #if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX // [macOS]
107
+ #if !TARGET_OS_UIKITFORMAC
130
108
 
109
+ #if !TARGET_OS_OSX // [macOS]
110
+ /** DEPRECATED. UILocalNotification was deprecated in iOS 10. Please don't add new callsites. */
131
111
  static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
132
112
  {
133
113
  NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
@@ -146,33 +126,7 @@ static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notificatio
146
126
  formattedLocalNotification[@"remote"] = @NO;
147
127
  return formattedLocalNotification;
148
128
  }
149
-
150
- static NSDictionary *RCTFormatUNNotification(UNNotification *notification)
151
- {
152
- NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
153
- UNNotificationContent *content = notification.request.content;
154
-
155
- formattedNotification[@"identifier"] = notification.request.identifier;
156
-
157
- if (notification.date) {
158
- NSDateFormatter *formatter = [NSDateFormatter new];
159
- [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
160
- NSString *dateString = [formatter stringFromDate:notification.date];
161
- formattedNotification[@"date"] = dateString;
162
- }
163
-
164
- formattedNotification[@"title"] = RCTNullIfNil(content.title);
165
- formattedNotification[@"body"] = RCTNullIfNil(content.body);
166
- formattedNotification[@"category"] = RCTNullIfNil(content.categoryIdentifier);
167
- formattedNotification[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
168
- formattedNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
169
-
170
- return formattedNotification;
171
- }
172
-
173
- #endif // TARGET_OS_UIKITFORMAC
174
- #if TARGET_OS_OSX // [macOS
175
-
129
+ #else // [macOS
176
130
  static NSDictionary *RCTFormatUserNotification(NSUserNotification *notification)
177
131
  {
178
132
  NSMutableDictionary *formattedUserNotification = [NSMutableDictionary dictionary];
@@ -192,6 +146,60 @@ static NSDictionary *RCTFormatUserNotification(NSUserNotification *notification)
192
146
  }
193
147
  #endif // macOS]
194
148
 
149
+ /** For delivered notifications */
150
+ static NSDictionary<NSString *, id> *RCTFormatUNNotification(UNNotification *notification)
151
+ {
152
+ NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
153
+ if (notification.date) {
154
+ formattedLocalNotification[@"fireDate"] = RCTFormatNotificationDateFromNSDate(notification.date);
155
+ }
156
+ [formattedLocalNotification addEntriesFromDictionary:RCTFormatUNNotificationContent(notification.request.content)];
157
+ return formattedLocalNotification;
158
+ }
159
+
160
+ /** For scheduled notification requests */
161
+ static NSDictionary<NSString *, id> *RCTFormatUNNotificationRequest(UNNotificationRequest *request)
162
+ {
163
+ NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
164
+ if (request.trigger) {
165
+ NSDate *triggerDate = nil;
166
+ if ([request.trigger isKindOfClass:[UNTimeIntervalNotificationTrigger class]]) {
167
+ triggerDate = [(UNTimeIntervalNotificationTrigger *)request.trigger nextTriggerDate];
168
+ } else if ([request.trigger isKindOfClass:[UNCalendarNotificationTrigger class]]) {
169
+ triggerDate = [(UNCalendarNotificationTrigger *)request.trigger nextTriggerDate];
170
+ }
171
+
172
+ if (triggerDate) {
173
+ formattedLocalNotification[@"fireDate"] = RCTFormatNotificationDateFromNSDate(triggerDate);
174
+ }
175
+ }
176
+ [formattedLocalNotification addEntriesFromDictionary:RCTFormatUNNotificationContent(request.content)];
177
+ return formattedLocalNotification;
178
+ }
179
+
180
+ static NSDictionary<NSString *, id> *RCTFormatUNNotificationContent(UNNotificationContent *content)
181
+ {
182
+ // Note: soundName is not set because this can't be read from UNNotificationSound.
183
+ // Note: alertAction is no longer relevant with UNNotification
184
+ NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
185
+ formattedLocalNotification[@"alertTitle"] = RCTNullIfNil(content.title);
186
+ formattedLocalNotification[@"alertBody"] = RCTNullIfNil(content.body);
187
+ formattedLocalNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
188
+ formattedLocalNotification[@"category"] = content.categoryIdentifier;
189
+ formattedLocalNotification[@"applicationIconBadgeNumber"] = content.badge;
190
+ formattedLocalNotification[@"remote"] = @NO;
191
+ return formattedLocalNotification;
192
+ }
193
+
194
+ static NSString *RCTFormatNotificationDateFromNSDate(NSDate *date)
195
+ {
196
+ NSDateFormatter *formatter = [NSDateFormatter new];
197
+ [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
198
+ return [formatter stringFromDate:date];
199
+ }
200
+
201
+ #endif // TARGET_OS_UIKITFORMAC
202
+
195
203
  RCT_EXPORT_MODULE()
196
204
 
197
205
  - (dispatch_queue_t)methodQueue
@@ -235,12 +243,6 @@ RCT_EXPORT_MODULE()
235
243
  ];
236
244
  }
237
245
 
238
- #if !TARGET_OS_OSX // [macOS]
239
- + (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
240
- {
241
- }
242
- #endif // [macOS]
243
-
244
246
  + (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
245
247
  {
246
248
  NSMutableString *hexString = [NSMutableString string];
@@ -278,16 +280,16 @@ RCT_EXPORT_MODULE()
278
280
  object:self
279
281
  userInfo:userInfo];
280
282
  }
283
+ #endif // [macOS]
281
284
 
285
+ #if !TARGET_OS_OSX // [macOS]
282
286
  + (void)didReceiveLocalNotification:(UILocalNotification *)notification
283
287
  {
284
288
  [[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
285
289
  object:self
286
290
  userInfo:RCTFormatLocalNotification(notification)];
287
291
  }
288
-
289
- #else // [macOS
290
-
292
+ #else // [macOS
291
293
  + (void)didReceiveUserNotification:(NSUserNotification *)notification
292
294
  {
293
295
  NSString *notificationName = notification.isRemote ? RCTRemoteNotificationReceived : kLocalNotificationReceived;
@@ -296,7 +298,6 @@ RCT_EXPORT_MODULE()
296
298
  object:self
297
299
  userInfo:userInfo];
298
300
  }
299
-
300
301
  #endif // macOS]
301
302
 
302
303
  - (void)handleLocalNotificationReceived:(NSNotification *)notification
@@ -306,15 +307,13 @@ RCT_EXPORT_MODULE()
306
307
 
307
308
  - (void)handleRemoteNotificationReceived:(NSNotification *)notification
308
309
  {
310
+ #if !TARGET_OS_OSX // [macOS]
309
311
  NSMutableDictionary *remoteNotification =
310
312
  [NSMutableDictionary dictionaryWithDictionary:notification.userInfo[@"notification"]];
311
- #if !TARGET_OS_OSX // [macOS]
312
313
  RCTRemoteNotificationCallback completionHandler = notification.userInfo[@"completionHandler"];
313
- #endif // [macOS]
314
314
  NSString *notificationId = [[NSUUID UUID] UUIDString];
315
315
  remoteNotification[@"notificationId"] = notificationId;
316
316
  remoteNotification[@"remote"] = @YES;
317
- #if !TARGET_OS_OSX // [macOS]
318
317
  if (completionHandler) {
319
318
  if (!self.remoteNotificationCallbacks) {
320
319
  // Lazy initialization
@@ -322,9 +321,9 @@ RCT_EXPORT_MODULE()
322
321
  }
323
322
  self.remoteNotificationCallbacks[notificationId] = completionHandler;
324
323
  }
325
- #endif // [macOS]
326
324
 
327
325
  [self sendEventWithName:@"remoteNotificationReceived" body:remoteNotification];
326
+ #endif // [macOS]
328
327
  }
329
328
 
330
329
  - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
@@ -343,9 +342,9 @@ RCT_EXPORT_MODULE()
343
342
  [self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
344
343
  }
345
344
 
346
- #if !TARGET_OS_OSX // [macOS]
347
345
  RCT_EXPORT_METHOD(onFinishRemoteNotification : (NSString *)notificationId fetchResult : (NSString *)fetchResult)
348
346
  {
347
+ #if !TARGET_OS_OSX // [macOS]
349
348
  UIBackgroundFetchResult result = [RCTConvert UIBackgroundFetchResult:fetchResult];
350
349
  RCTRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
351
350
  if (!completionHandler) {
@@ -354,8 +353,8 @@ RCT_EXPORT_METHOD(onFinishRemoteNotification : (NSString *)notificationId fetchR
354
353
  }
355
354
  completionHandler(result);
356
355
  [self.remoteNotificationCallbacks removeObjectForKey:notificationId];
357
- }
358
356
  #endif // [macOS]
357
+ }
359
358
 
360
359
  /**
361
360
  * Update the application icon badge number on the home screen
@@ -401,33 +400,19 @@ RCT_EXPORT_METHOD(requestPermissions
401
400
  // Add a listener to make sure that startObserving has been called
402
401
  [self addListener:@"remoteNotificationsRegistered"];
403
402
 
404
- #if !TARGET_OS_OSX // [macOS
405
- UIUserNotificationType types = UIUserNotificationTypeNone;
403
+ UNAuthorizationOptions options = UNAuthorizationOptionNone;
406
404
 
407
405
  if (permissions.alert()) {
408
- types |= UIUserNotificationTypeAlert;
406
+ options |= UNAuthorizationOptionAlert;
409
407
  }
410
408
  if (permissions.badge()) {
411
- types |= UIUserNotificationTypeBadge;
409
+ options |= UNAuthorizationOptionBadge;
412
410
  }
413
411
  if (permissions.sound()) {
414
- types |= UIUserNotificationTypeSound;
412
+ options |= UNAuthorizationOptionSound;
415
413
  }
416
- #else
417
- NSRemoteNotificationType types = NSRemoteNotificationTypeNone;
418
-
419
- if (permissions.alert()) {
420
- types |= NSRemoteNotificationTypeAlert;
421
- }
422
- if (permissions.badge()) {
423
- types |= NSRemoteNotificationTypeBadge;
424
- }
425
- if (permissions.sound()) {
426
- types |= NSRemoteNotificationTypeSound;
427
- }
428
- #endif // macOS]
429
414
  [UNUserNotificationCenter.currentNotificationCenter
430
- requestAuthorizationWithOptions:types
415
+ requestAuthorizationWithOptions:options
431
416
  completionHandler:^(BOOL granted, NSError *_Nullable error) {
432
417
  if (error != NULL) {
433
418
  reject(@"-1", @"Error - Push authorization request failed.", error);
@@ -496,108 +481,87 @@ static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(
496
481
  };
497
482
  }
498
483
 
499
- #if !TARGET_OS_OSX // [macOS]
500
484
  RCT_EXPORT_METHOD(presentLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
501
485
  {
502
- NSMutableDictionary *notificationDict = [NSMutableDictionary new];
503
- notificationDict[@"alertTitle"] = notification.alertTitle();
504
- notificationDict[@"alertBody"] = notification.alertBody();
505
- notificationDict[@"alertAction"] = notification.alertAction();
506
- notificationDict[@"userInfo"] = notification.userInfo();
507
- notificationDict[@"category"] = notification.category();
508
- notificationDict[@"repeatInterval"] = notification.repeatInterval();
509
- if (notification.fireDate()) {
510
- notificationDict[@"fireDate"] = @(*notification.fireDate());
511
- }
512
- if (notification.applicationIconBadgeNumber()) {
513
- notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
514
- }
515
- if (notification.isSilent()) {
516
- notificationDict[@"isSilent"] = @(*notification.isSilent());
517
- if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) {
518
- notificationDict[@"soundName"] = notification.soundName();
519
- }
520
- }
521
- [RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]];
522
- }
523
- #else // [macOS
524
- RCT_EXPORT_METHOD(presentLocalNotification:(NSUserNotification *)notification)
525
- {
526
- [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
486
+ NSDictionary<NSString *, id> *notificationDict = [RCTConvert NSDictionaryForNotification:notification];
487
+ UNNotificationContent *content = [RCTConvert UNNotificationContent:notificationDict];
488
+ UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1
489
+ repeats:NO];
490
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
491
+ content:content
492
+ trigger:trigger];
493
+
494
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
495
+ [center addNotificationRequest:request withCompletionHandler:nil];
527
496
  }
528
- #endif // macOS]
529
497
 
530
- #if !TARGET_OS_OSX // [macOS]
531
498
  RCT_EXPORT_METHOD(scheduleLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
532
499
  {
533
- NSMutableDictionary *notificationDict = [NSMutableDictionary new];
534
- notificationDict[@"alertTitle"] = notification.alertTitle();
535
- notificationDict[@"alertBody"] = notification.alertBody();
536
- notificationDict[@"alertAction"] = notification.alertAction();
537
- notificationDict[@"userInfo"] = notification.userInfo();
538
- notificationDict[@"category"] = notification.category();
539
- notificationDict[@"repeatInterval"] = notification.repeatInterval();
540
- if (notification.fireDate()) {
541
- notificationDict[@"fireDate"] = @(*notification.fireDate());
542
- }
543
- if (notification.applicationIconBadgeNumber()) {
544
- notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
545
- }
546
- if (notification.isSilent()) {
547
- notificationDict[@"isSilent"] = @(*notification.isSilent());
548
- if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) {
549
- notificationDict[@"soundName"] = notification.soundName();
550
- }
500
+ NSDictionary<NSString *, id> *notificationDict = [RCTConvert NSDictionaryForNotification:notification];
501
+ UNNotificationContent *content = [RCTConvert UNNotificationContent:notificationDict];
502
+
503
+ UNNotificationTrigger *trigger = nil;
504
+ if (notificationDict[@"fireDate"]) {
505
+ NSDate *fireDate = [RCTConvert NSDate:notificationDict[@"fireDate"]] ?: [NSDate date];
506
+ NSCalendar *calendar = [NSCalendar currentCalendar];
507
+ NSDateComponents *components =
508
+ [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour |
509
+ NSCalendarUnitMinute | NSCalendarUnitSecond)
510
+ fromDate:fireDate];
511
+ trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
512
+ } else if (notificationDict[@"fireIntervalSeconds"]) {
513
+ trigger = [UNTimeIntervalNotificationTrigger
514
+ triggerWithTimeInterval:[notificationDict[@"fireIntervalSeconds"] doubleValue]
515
+ repeats:NO];
551
516
  }
552
- [RCTSharedApplication() scheduleLocalNotification:[RCTConvert UILocalNotification:notificationDict]];
553
- }
554
- #else // [macOS
555
- RCT_EXPORT_METHOD(scheduleLocalNotification:(NSUserNotification *)notification)
556
- {
557
- [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
517
+
518
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
519
+ content:content
520
+ trigger:trigger];
521
+
522
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
523
+ [center addNotificationRequest:request withCompletionHandler:nil];
558
524
  }
559
- #endif // macOS]
560
525
 
561
526
  RCT_EXPORT_METHOD(cancelAllLocalNotifications)
562
527
  {
563
- #if !TARGET_OS_OSX // [macOS]
564
- [RCTSharedApplication() cancelAllLocalNotifications];
565
- #else // [macOS
566
- for (NSUserNotification *notif in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications) {
567
- [[NSUserNotificationCenter defaultUserNotificationCenter] removeScheduledNotification:notif];
568
- }
569
- #endif // macOS]
528
+ [[UNUserNotificationCenter currentNotificationCenter]
529
+ getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *requests) {
530
+ NSMutableArray<NSString *> *notificationIdentifiersToCancel = [NSMutableArray new];
531
+ for (UNNotificationRequest *request in requests) {
532
+ [notificationIdentifiersToCancel addObject:request.identifier];
533
+ }
534
+ [[UNUserNotificationCenter currentNotificationCenter]
535
+ removePendingNotificationRequestsWithIdentifiers:notificationIdentifiersToCancel];
536
+ }];
570
537
  }
571
538
 
572
539
  RCT_EXPORT_METHOD(cancelLocalNotifications : (NSDictionary<NSString *, id> *)userInfo)
573
540
  {
574
- #if !TARGET_OS_OSX // [macOS]
575
- for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
576
- #else // [macOS
577
- for (NSUserNotification *notification in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications) {
578
- #endif // macOS]
579
- __block BOOL matchesAll = YES;
580
- NSDictionary<NSString *, id> *notificationInfo = notification.userInfo;
581
- // Note: we do this with a loop instead of just `isEqualToDictionary:`
582
- // because we only require that all specified userInfo values match the
583
- // notificationInfo values - notificationInfo may contain additional values
584
- // which we don't care about.
585
- [userInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
586
- if (![notificationInfo[key] isEqual:obj]) {
587
- matchesAll = NO;
588
- *stop = YES;
541
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
542
+ [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *_Nonnull requests) {
543
+ NSMutableArray<NSString *> *notificationIdentifiersToCancel = [NSMutableArray new];
544
+ for (UNNotificationRequest *request in requests) {
545
+ NSDictionary<NSString *, id> *notificationInfo = request.content.userInfo;
546
+ // Note: we do this with a loop instead of just `isEqualToDictionary:`
547
+ // because we only require that all specified userInfo values match the
548
+ // notificationInfo values - notificationInfo may contain additional values
549
+ // which we don't care about.
550
+ __block BOOL shouldCancel = YES;
551
+ [userInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
552
+ if (![notificationInfo[key] isEqual:obj]) {
553
+ shouldCancel = NO;
554
+ *stop = YES;
555
+ }
556
+ }];
557
+
558
+ if (shouldCancel) {
559
+ [notificationIdentifiersToCancel addObject:request.identifier];
589
560
  }
590
- }];
591
- #if !TARGET_OS_OSX // [macOS]
592
- if (matchesAll) {
593
- [RCTSharedApplication() cancelLocalNotification:notification];
594
- }
595
- #else // [macOS
596
- if ([notification.identifier isEqualToString:userInfo[@"identifier"]] || matchesAll) {
597
- [[NSUserNotificationCenter defaultUserNotificationCenter] removeScheduledNotification:notification];
598
561
  }
599
- #endif // macOS]
600
- }
562
+
563
+ [center removePendingNotificationRequestsWithIdentifiers:notificationIdentifiersToCancel];
564
+ }];
601
565
  }
602
566
 
603
567
  RCT_EXPORT_METHOD(getInitialNotification
@@ -631,50 +595,30 @@ RCT_EXPORT_METHOD(getInitialNotification
631
595
 
632
596
  RCT_EXPORT_METHOD(getScheduledLocalNotifications : (RCTResponseSenderBlock)callback)
633
597
  {
634
- #if !TARGET_OS_OSX // [macOS]
635
- NSArray<UILocalNotification *> *scheduledLocalNotifications = RCTSharedApplication().scheduledLocalNotifications;
636
- #endif // [macOS]
637
- NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
638
- #if !TARGET_OS_OSX // [macOS]
639
- for (UILocalNotification *notification in scheduledLocalNotifications) {
640
- [formattedScheduledLocalNotifications addObject:RCTFormatLocalNotification(notification)];
641
- }
642
- #else // [macOS
643
- for (NSUserNotification *notification in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications) {
644
- [formattedScheduledLocalNotifications addObject:RCTFormatUserNotification(notification)];
645
- }
646
- #endif // macOS]
647
- callback(@[ formattedScheduledLocalNotifications ]);
598
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
599
+ [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *_Nonnull requests) {
600
+ NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
601
+ for (UNNotificationRequest *request in requests) {
602
+ [formattedScheduledLocalNotifications addObject:RCTFormatUNNotificationRequest(request)];
603
+ }
604
+ callback(@[ formattedScheduledLocalNotifications ]);
605
+ }];
648
606
  }
649
607
 
650
608
  RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
651
609
  {
652
- #if !TARGET_OS_OSX // [macOS]
653
610
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
654
611
  [center removeAllDeliveredNotifications];
655
- #else // [macOS
656
- [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
657
- #endif // macOS]
658
612
  }
659
613
 
660
614
  RCT_EXPORT_METHOD(removeDeliveredNotifications : (NSArray<NSString *> *)identifiers)
661
615
  {
662
- #if !TARGET_OS_OSX // [macOS]
663
616
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
664
617
  [center removeDeliveredNotificationsWithIdentifiers:identifiers];
665
- #else // [macOS
666
- NSArray<NSUserNotification*> *notificationsToRemove = [[NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSUserNotification* evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
667
- return [identifiers containsObject:evaluatedObject.identifier];
668
- }]];
669
- for (NSUserNotification *notification in notificationsToRemove) {
670
- [[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:notification];
671
- }
672
- #endif // macOS]
673
618
  }
674
619
 
675
620
  RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
676
621
  {
677
- #if !TARGET_OS_OSX // [macOS]
678
622
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
679
623
  [center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *_Nonnull notifications) {
680
624
  NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
@@ -684,13 +628,6 @@ RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
684
628
  }
685
629
  callback(@[ formattedNotifications ]);
686
630
  }];
687
- #else // [macOS
688
- NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
689
- for (NSUserNotification *notification in [NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications) {
690
- [formattedNotifications addObject:RCTFormatUserNotification(notification)];
691
- }
692
- callback(@[formattedNotifications]);
693
- #endif // macOS]
694
631
  }
695
632
 
696
633
  RCT_EXPORT_METHOD(getAuthorizationStatus : (RCTResponseSenderBlock)callback)
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(73),
26
- RCTVersionPatch: @(4),
26
+ RCTVersionPatch: @(5),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.73.4
1
+ VERSION_NAME=0.73.5
2
2
  react.internal.publishingGroup=com.facebook.react
3
3
 
4
4
  android.useAndroidX=true
@@ -17,6 +17,6 @@ public class ReactNativeVersion {
17
17
  public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
18
18
  "major", 0,
19
19
  "minor", 73,
20
- "patch", 4,
20
+ "patch", 5,
21
21
  "prerelease", null);
22
22
  }
@@ -17,7 +17,7 @@ namespace facebook::react {
17
17
  constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 73;
20
- int32_t Patch = 4;
20
+ int32_t Patch = 5;
21
21
  std::string_view Prerelease = "";
22
22
  } ReactNativeVersion;
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.73.4",
3
+ "version": "0.73.5",
4
4
  "description": "React Native for macOS",
5
5
  "license": "MIT",
6
6
  "repository": {