@@ -34,20 +34,22 @@ @implementation RCTConvert (UNNotificationContent)
3434+ (UNNotificationContent *)UNNotificationContent : (id )json
3535{
3636 NSDictionary <NSString *, id > *details = [self NSDictionary: json];
37- BOOL isSilent = [RCTConvert BOOL: details[@" isSilent" ]];
3837 UNMutableNotificationContent *content = [UNMutableNotificationContent new ];
38+ #if !TARGET_OS_TV
39+ BOOL isSilent = [RCTConvert BOOL: details[@" isSilent" ]];
3940 content.title = [RCTConvert NSString: details[@" alertTitle" ]];
4041 content.body = [RCTConvert NSString: details[@" alertBody" ]];
4142 content.userInfo = [RCTConvert NSDictionary: details[@" userInfo" ]];
4243 content.categoryIdentifier = [RCTConvert NSString: details[@" category" ]];
43- if (details[@" applicationIconBadgeNumber" ]) {
44- content.badge = [RCTConvert NSNumber: details[@" applicationIconBadgeNumber" ]];
45- }
4644 if (!isSilent) {
4745 NSString *soundName = [RCTConvert NSString: details[@" soundName" ]];
4846 content.sound =
4947 soundName ? [UNNotificationSound soundNamed: details[@" soundName" ]] : [UNNotificationSound defaultSound ];
5048 }
49+ #endif
50+ if (details[@" applicationIconBadgeNumber" ]) {
51+ content.badge = [RCTConvert NSNumber: details[@" applicationIconBadgeNumber" ]];
52+ }
5153
5254 return content;
5355}
@@ -133,10 +135,12 @@ @implementation RCTPushNotificationManager
133135 // Note: soundName is not set because this can't be read from UNNotificationSound.
134136 // Note: alertAction is no longer relevant with UNNotification
135137 NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary ];
138+ #if !TARGET_OS_TV
136139 formattedLocalNotification[@" alertTitle" ] = RCTNullIfNil (content.title );
137140 formattedLocalNotification[@" alertBody" ] = RCTNullIfNil (content.body );
138141 formattedLocalNotification[@" userInfo" ] = RCTNullIfNil (RCTJSONClean (content.userInfo ));
139142 formattedLocalNotification[@" category" ] = content.categoryIdentifier ;
143+ #endif
140144 formattedLocalNotification[@" applicationIconBadgeNumber" ] = content.badge ;
141145 formattedLocalNotification[@" remote" ] = @NO ;
142146 return formattedLocalNotification;
@@ -220,10 +224,12 @@ + (void)didReceiveNotification:(UNNotification *)notification
220224{
221225 BOOL const isRemoteNotification = IsNotificationRemote (notification);
222226 if (isRemoteNotification) {
227+ #if !TARGET_OS_TV
223228 NSDictionary *userInfo = @{@" notification" : notification.request .content .userInfo };
224229 [[NSNotificationCenter defaultCenter ] postNotificationName: RCTRemoteNotificationReceived
225230 object: self
226231 userInfo: userInfo];
232+ #endif
227233 } else {
228234 [[NSNotificationCenter defaultCenter ] postNotificationName: kLocalNotificationReceived
229235 object: self
@@ -392,6 +398,10 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
392398
393399static inline NSDictionary *RCTPromiseResolveValueForUNNotificationSettings (UNNotificationSettings *_Nonnull settings)
394400{
401+ #if TARGET_OS_TV
402+ return RCTSettingsDictForUNNotificationSettings (
403+ NO , settings.badgeSetting == UNNotificationSettingEnabled , NO , NO , NO , NO , settings.authorizationStatus );
404+ #else
395405 return RCTSettingsDictForUNNotificationSettings (
396406 settings.alertSetting == UNNotificationSettingEnabled ,
397407 settings.badgeSetting == UNNotificationSettingEnabled ,
@@ -400,6 +410,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
400410 settings.lockScreenSetting == UNNotificationSettingEnabled ,
401411 settings.notificationCenterSetting == UNNotificationSettingEnabled ,
402412 settings.authorizationStatus );
413+ #endif
403414}
404415
405416static inline NSDictionary *RCTSettingsDictForUNNotificationSettings (
@@ -479,6 +490,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
479490
480491RCT_EXPORT_METHOD (cancelLocalNotifications : (NSDictionary <NSString *, id > *)userInfo)
481492{
493+ #if !TARGET_OS_TV
482494 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
483495 [center getPendingNotificationRequestsWithCompletionHandler: ^(NSArray <UNNotificationRequest *> *_Nonnull requests) {
484496 NSMutableArray <NSString *> *notificationIdentifiersToCancel = [NSMutableArray new ];
@@ -503,6 +515,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
503515
504516 [center removePendingNotificationRequestsWithIdentifiers: notificationIdentifiersToCancel];
505517 }];
518+ #endif
506519}
507520
508521RCT_EXPORT_METHOD (
@@ -543,18 +556,23 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
543556
544557RCT_EXPORT_METHOD (removeAllDeliveredNotifications)
545558{
559+ #if !TARGET_OS_TV
546560 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
547561 [center removeAllDeliveredNotifications ];
562+ #endif
548563}
549564
550565RCT_EXPORT_METHOD (removeDeliveredNotifications : (NSArray <NSString *> *)identifiers)
551566{
567+ #if !TARGET_OS_TV
552568 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
553569 [center removeDeliveredNotificationsWithIdentifiers: identifiers];
570+ #endif
554571}
555572
556573RCT_EXPORT_METHOD (getDeliveredNotifications : (RCTResponseSenderBlock)callback)
557574{
575+ #if !TARGET_OS_TV
558576 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
559577 [center getDeliveredNotificationsWithCompletionHandler: ^(NSArray <UNNotification *> *_Nonnull notifications) {
560578 NSMutableArray <NSDictionary *> *formattedNotifications = [NSMutableArray new ];
@@ -564,6 +582,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
564582 }
565583 callback (@[ formattedNotifications ]);
566584 }];
585+ #else
586+ callback (@[ @[] ]);
587+ #endif
567588}
568589
569590RCT_EXPORT_METHOD (getAuthorizationStatus : (RCTResponseSenderBlock)callback)
0 commit comments