Commit a9215e75 authored by Libin Lu's avatar Libin Lu Committed by GitHub

Merge pull request #517 from douglasjunior/patch-1

Allow local notification without sound (Android and iOS)
parents bb63b523 5b079c1b
...@@ -82,7 +82,6 @@ public class FIRLocalMessagingHelper { ...@@ -82,7 +82,6 @@ public class FIRLocalMessagingHelper {
.setSubText(bundle.getString("sub_text")) .setSubText(bundle.getString("sub_text"))
.setGroup(bundle.getString("group")) .setGroup(bundle.getString("group"))
.setVibrate(new long[]{0, DEFAULT_VIBRATION}) .setVibrate(new long[]{0, DEFAULT_VIBRATION})
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setExtras(bundle.getBundle("data")); .setExtras(bundle.getBundle("data"));
//priority //priority
...@@ -151,14 +150,18 @@ public class FIRLocalMessagingHelper { ...@@ -151,14 +150,18 @@ public class FIRLocalMessagingHelper {
} }
//sound //sound
String soundName = bundle.getString("sound", "default"); String soundName = bundle.getString("sound");
if (!soundName.equalsIgnoreCase("default")) { if (soundName != null) {
int soundResourceId = res.getIdentifier(soundName, "raw", packageName); if (soundName.equalsIgnoreCase("default")) {
if(soundResourceId == 0){ notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
soundName = soundName.substring(0, soundName.lastIndexOf('.')); } else {
soundResourceId = res.getIdentifier(soundName, "raw", packageName); int soundResourceId = res.getIdentifier(soundName, "raw", packageName);
if (soundResourceId == 0) {
soundName = soundName.substring(0, soundName.lastIndexOf('.'));
soundResourceId = res.getIdentifier(soundName, "raw", packageName);
}
notification.setSound(Uri.parse("android.resource://" + packageName + "/" + soundResourceId));
} }
notification.setSound(Uri.parse("android.resource://" + packageName + "/" + soundResourceId));
} }
//color //color
......
...@@ -45,9 +45,11 @@ RCT_ENUM_CONVERTER(NSCalendarUnit, ...@@ -45,9 +45,11 @@ RCT_ENUM_CONVERTER(NSCalendarUnit,
content.body =[RCTConvert NSString:details[@"body"]]; content.body =[RCTConvert NSString:details[@"body"]];
NSString* sound = [RCTConvert NSString:details[@"sound"]]; NSString* sound = [RCTConvert NSString:details[@"sound"]];
if(sound != nil){ if(sound != nil){
content.sound = [UNNotificationSound soundNamed:sound]; if ([sound isEqual:@"default"]) {
}else{ content.sound = [UNNotificationSound defaultSound];
content.sound = [UNNotificationSound defaultSound]; } else {
content.sound = [UNNotificationSound soundNamed:sound];
}
} }
content.categoryIdentifier = [RCTConvert NSString:details[@"click_action"]]; content.categoryIdentifier = [RCTConvert NSString:details[@"click_action"]];
content.userInfo = details; content.userInfo = details;
......
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