Commit aa1a7b94 authored by Ran Greenberg's avatar Ran Greenberg Committed by GitHub

Merge pull request #116 from reberhardt7/add-silent-option

Add silent option to iOS localNotification
parents 449c2f77 358c1ec5
...@@ -327,6 +327,7 @@ let localNotification = NotificationsIOS.localNotification({ ...@@ -327,6 +327,7 @@ let localNotification = NotificationsIOS.localNotification({
alertBody: "Local notificiation!", alertBody: "Local notificiation!",
alertTitle: "Local Notification Title", alertTitle: "Local Notification Title",
soundName: "chime.aiff", soundName: "chime.aiff",
silent: false,
category: "SOME_CATEGORY", category: "SOME_CATEGORY",
userInfo: { } userInfo: { }
}); });
...@@ -338,7 +339,8 @@ Notification object contains: ...@@ -338,7 +339,8 @@ Notification object contains:
- `alertBody`- The message displayed in the notification alert. - `alertBody`- The message displayed in the notification alert.
- `alertTitle`- The title of the notification, displayed in the notifications center. - `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. - `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). - `category`- The category of this notification, required for [interactive notifications](#interactive--actionable-notifications-ios-only) (optional).
- `userInfo`- An optional object containing additional notification data. - `userInfo`- An optional object containing additional notification data.
......
...@@ -103,6 +103,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{ ...@@ -103,6 +103,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{
notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]]; notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
notification.alertAction = [RCTConvert NSString:details[@"alertAction"]]; notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName; notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
if ([RCTConvert BOOL:details[@"silent"]]) {
notification.soundName = nil;
}
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{}; notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{};
notification.category = [RCTConvert NSString:details[@"category"]]; notification.category = [RCTConvert NSString:details[@"category"]];
...@@ -121,6 +124,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{ ...@@ -121,6 +124,9 @@ RCT_ENUM_CONVERTER(UIUserNotificationActionBehavior, (@{
content.sound = [RCTConvert NSString:details[@"soundName"]] content.sound = [RCTConvert NSString:details[@"soundName"]]
? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"soundName"]]] ? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"soundName"]]]
: [UNNotificationSound defaultSound]; : [UNNotificationSound defaultSound];
if ([RCTConvert BOOL:details[@"silent"]]) {
content.sound = nil;
}
content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{}; content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]] ?: @{};
content.categoryIdentifier = [RCTConvert NSString:details[@"category"]]; content.categoryIdentifier = [RCTConvert NSString:details[@"category"]];
......
...@@ -190,6 +190,7 @@ export default class NotificationsIOS { ...@@ -190,6 +190,7 @@ export default class NotificationsIOS {
* - `alertTitle` : The message title displayed in the notification. * - `alertTitle` : The message title displayed in the notification.
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view"; * - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
* - `soundName` : The sound played when the notification is fired (optional). * - `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). * - `category` : The category of this notification, required for actionable notifications (optional).
* - `userInfo` : An optional object containing additional notification data. * - `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. * - `fireDate` : The date and time when the system should deliver the notification. if not specified, the notification will be dispatched immediately.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment