mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Play sound in local notification only if soundName is specified
Summary: Currently it's not possible to create a silent local notification (which is useful for badge updates) with PushNotificationIOS. This commit solves the problem - when **soundName** param is not specified in **PushNotificationIOS.scheduleLocalNotification** method, a silent notification will be created. Local notification without sound: ``` let fireDate = new Date(); fireDate = fireDate.setSeconds(fireDate.getSeconds() + 15); //fire in 15 seconds PushNotificationIOS.scheduleLocalNotification({ fireDate: fireDate, alertBody: "I'm silent!" }); ``` Local notification with sound: ``` let fireDate = new Date(); fireDate = fireDate.setSeconds(fireDate.getSeconds() + 15); //fire in 15 seconds PushNotificationIOS.scheduleLocalNotification({ fireDate: fireDate, alertBody: "I'm with sound!", soundName: "Any sound" }); ``` Closes https://github.com/facebook/react-native/pull/13734 Differential Revision: D5144848 Pulled By: shergin fbshipit-source-id: dc990b2673305a01cfd868fcdedcf27c461d0a34
This commit is contained in:
parent
daf3bd1b88
commit
9fae268e5b
@ -140,6 +140,7 @@ class PushNotificationIOS {
|
||||
* - `alertBody` : The message displayed in the notification alert.
|
||||
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
|
||||
* - `soundName` : The sound played when the notification is fired (optional).
|
||||
* - `isSilent` : If true, the notification will appear without sound (optional).
|
||||
* - `category` : The category of this notification, required for actionable notifications (optional).
|
||||
* - `userInfo` : An optional object containing additional notification data.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed.
|
||||
@ -157,6 +158,7 @@ class PushNotificationIOS {
|
||||
* - `alertBody` : The message displayed in the notification alert.
|
||||
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
|
||||
* - `soundName` : The sound played when the notification is fired (optional).
|
||||
* - `isSilent` : If true, the notification will appear without sound (optional).
|
||||
* - `category` : The category of this notification, required for actionable notifications (optional).
|
||||
* - `userInfo` : An optional object containing additional notification data.
|
||||
* - `applicationIconBadgeNumber` (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge.
|
||||
|
@ -50,17 +50,20 @@ RCT_ENUM_CONVERTER(NSCalendarUnit,
|
||||
+ (UILocalNotification *)UILocalNotification:(id)json
|
||||
{
|
||||
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
|
||||
BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
|
||||
UILocalNotification *notification = [UILocalNotification new];
|
||||
notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
|
||||
notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
|
||||
notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
|
||||
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
|
||||
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
|
||||
notification.category = [RCTConvert NSString:details[@"category"]];
|
||||
notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
|
||||
if (details[@"applicationIconBadgeNumber"]) {
|
||||
notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]];
|
||||
}
|
||||
if (!isSilent) {
|
||||
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
|
||||
}
|
||||
return notification;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user