diff --git a/README.md b/README.md index 641a32944696cbdd980648fa823c8c3069e1a223..341dc074e316b232f2ef82fde2f9e7595196944d 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,7 @@ let localNotification = NotificationsIOS.localNotification({ alertBody: "Local notificiation!", alertTitle: "Local Notification Title", soundName: "chime.aiff", + silent: false, category: "SOME_CATEGORY", userInfo: { } }); @@ -338,7 +339,8 @@ Notification object contains: - `alertBody`- The message displayed in the notification alert. - `alertTitle`- The title of the notification, displayed in the notifications center. - `alertAction`- The "action" displayed beneath an actionable notification on the lockscreen (e.g. "Slide to **open**"). Note that Apple no longer shows this in iOS 10. -- `soundName`- The sound played when the notification is fired (optional). +- `soundName`- The sound played when the notification is fired (optional -- will play default sound if unspecified). This must be the filename of a sound included in the application bundle; the sound must be 30 seconds or less and should be encoded with linear PCM or IMA4. +- `silent`- Whether the notification sound should be suppressed (optional). - `category`- The category of this notification, required for [interactive notifications](#interactive--actionable-notifications-ios-only) (optional). - `userInfo`- An optional object containing additional notification data. diff --git a/RNNotifications/RNNotifications.m b/RNNotifications/RNNotifications.m index 3c12a9dbcb5db7580cf4cc4cd81abecaf8dda8c5..d50a7ce6e40f46b4f638e2e85bda5e5b4b0456a1 100644 --- a/RNNotifications/RNNotifications.m +++ b/RNNotifications/RNNotifications.m @@ -103,6 +103,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{ notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]]; notification.alertAction = [RCTConvert NSString:details[@"alertAction"]]; notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName; + if ([RCTConvert BOOL:details[@"silent"]]) { + notification.soundName = nil; + } notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{}; notification.category = [RCTConvert NSString:details[@"category"]]; @@ -121,6 +124,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{ content.sound = [RCTConvert NSString:details[@"soundName"]] ? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"soundName"]]] : [UNNotificationSound defaultSound]; + if ([RCTConvert BOOL:details[@"silent"]]) { + content.sound = nil; + } content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{}; content.categoryIdentifier = [RCTConvert NSString:details[@"category"]]; diff --git a/index.ios.js b/index.ios.js index d5ac85686d636caa6e814b8d0b4716d0eb3b19dc..3450e9955c46a92d8eafaf02776c39291159ae7e 100644 --- a/index.ios.js +++ b/index.ios.js @@ -190,6 +190,7 @@ export default class NotificationsIOS { * - `alertTitle` : The message title displayed in the notification. * - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view"; * - `soundName` : The sound played when the notification is fired (optional). + * - `silent` : If true, the notification sound will be suppressed (optional). * - `category` : The category of this notification, required for actionable notifications (optional). * - `userInfo` : An optional object containing additional notification data. * - `fireDate` : The date and time when the system should deliver the notification. if not specified, the notification will be dispatched immediately.