From eb1949948406195c4c02c6041d07cba074ae820c Mon Sep 17 00:00:00 2001 From: Moses DeJong Date: Fri, 4 Feb 2022 18:14:31 -0800 Subject: [PATCH] Enable custom sound for local notification in PushNotificationIOS Summary: Add soundName property in NativePushNotificationManagerIOS JS module and deliver to native local notification API. Changelog: [iOS][Fixed] - Enable custom sound for local push notifications. Reviewed By: RSNara Differential Revision: D33898630 fbshipit-source-id: c6362032601f0f6d20479465ce1f0a84c450ea72 --- .../PushNotificationIOS/NativePushNotificationManagerIOS.js | 1 + Libraries/PushNotificationIOS/RCTPushNotificationManager.mm | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js b/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js index e4252de820a1a6..93f79effa9adb3 100644 --- a/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js +++ b/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js @@ -29,6 +29,7 @@ type Notification = {| +repeatInterval?: ?string, +applicationIconBadgeNumber?: ?number, +isSilent?: ?boolean, + +soundName?: ?string, |}; export interface Spec extends TurboModule { diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm index 21d613b5b3e46c..d767641cd22768 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm @@ -367,6 +367,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification } if (notification.isSilent()) { notificationDict[@"isSilent"] = @(*notification.isSilent()); + if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) { + notificationDict[@"soundName"] = notification.soundName(); + } } [RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]]; } @@ -388,6 +391,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification } if (notification.isSilent()) { notificationDict[@"isSilent"] = @(*notification.isSilent()); + if ([notificationDict[@"isSilent"] isEqualToNumber:@(NO)]) { + notificationDict[@"soundName"] = notification.soundName(); + } } [RCTSharedApplication() scheduleLocalNotification:[RCTConvert UILocalNotification:notificationDict]]; }