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