Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit f2dd349

Browse files
committed
Add an example with sound in project example.
1 parent 4899349 commit f2dd349

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

example/App.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,27 @@ export default class App extends Component {
4949
}}>
5050
<Text>Local Notification (now)</Text>
5151
</TouchableOpacity>
52+
<TouchableOpacity
53+
style={styles.button}
54+
onPress={() => {
55+
this.notif.localNotif('sample.mp3');
56+
}}>
57+
<Text>Local Notification with sound (now)</Text>
58+
</TouchableOpacity>
5259
<TouchableOpacity
5360
style={styles.button}
5461
onPress={() => {
5562
this.notif.scheduleNotif();
5663
}}>
5764
<Text>Schedule Notification in 30s</Text>
5865
</TouchableOpacity>
66+
<TouchableOpacity
67+
style={styles.button}
68+
onPress={() => {
69+
this.notif.scheduleNotif('sample.mp3');
70+
}}>
71+
<Text>Schedule Notification with sound in 30s</Text>
72+
</TouchableOpacity>
5973
<TouchableOpacity
6074
style={styles.button}
6175
onPress={() => {

example/NotifService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class NotifService {
99
NotificationHandler.attachNotification(onNotification);
1010
}
1111

12-
localNotif() {
12+
localNotif(soundName) {
1313
this.lastId++;
1414
PushNotification.localNotification({
1515
/* Android Only Properties */
@@ -35,14 +35,14 @@ export default class NotifService {
3535
/* iOS and Android properties */
3636
title: 'Local Notification', // (optional)
3737
message: 'My Notification Message', // (required)
38-
playSound: false, // (optional) default: true
39-
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
38+
playSound: !!soundName, // (optional) default: true
39+
soundName: soundName ? soundName : 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
4040
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
4141
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
4242
});
4343
}
4444

45-
scheduleNotif() {
45+
scheduleNotif(soundName) {
4646
this.lastId++;
4747
PushNotification.localNotificationSchedule({
4848
date: new Date(Date.now() + 30 * 1000), // in 30 secs
@@ -70,8 +70,8 @@ export default class NotifService {
7070
/* iOS and Android properties */
7171
title: 'Scheduled Notification', // (optional)
7272
message: 'My Notification Message', // (required)
73-
playSound: true, // (optional) default: true
74-
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
73+
playSound: !!soundName, // (optional) default: true
74+
soundName: soundName ? soundName : 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
7575
});
7676
}
7777

50.3 KB
Binary file not shown.

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
4303B027D05E61B36AF2D9DA /* libPods-example-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D89C42625470FE853701396C /* libPods-example-tvOS.a */; };
2121
4BF20923B09DA7D7C7D74054 /* libPods-example-exampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F3EFF15EA907A6500887787 /* libPods-example-exampleTests.a */; };
2222
66172E2B135131DB9C88C137 /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 67C595176EF92CCFA00C1943 /* libPods-example.a */; };
23+
AECB905824658DC600ED1B83 /* sample.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AECB905724658DC600ED1B83 /* sample.mp3 */; };
2324
/* End PBXBuildFile section */
2425

2526
/* Begin PBXContainerItemProxy section */
@@ -62,6 +63,7 @@
6263
67C595176EF92CCFA00C1943 /* libPods-example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
6364
68FB3463CAEF28E88730ADEE /* Pods-example-tvOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOSTests.release.xcconfig"; path = "Target Support Files/Pods-example-tvOSTests/Pods-example-tvOSTests.release.xcconfig"; sourceTree = "<group>"; };
6465
ACCB69D76B81B3D29BE3BB2B /* libPods-example-tvOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
66+
AECB905724658DC600ED1B83 /* sample.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = sample.mp3; sourceTree = "<group>"; };
6567
AED90B1C243E6D21006F11F7 /* example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = example.entitlements; path = example/example.entitlements; sourceTree = "<group>"; };
6668
B43E6CF3919EF7ACAF9CC8B7 /* Pods-example-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-example-tvOS/Pods-example-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
6769
C528DBA88EA5CBFA010ECC73 /* Pods-example-exampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.release.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.release.xcconfig"; sourceTree = "<group>"; };
@@ -126,6 +128,7 @@
126128
13B07FAE1A68108700A75B9A /* example */ = {
127129
isa = PBXGroup;
128130
children = (
131+
AECB905724658DC600ED1B83 /* sample.mp3 */,
129132
AED90B1C243E6D21006F11F7 /* example.entitlements */,
130133
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
131134
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
@@ -341,6 +344,7 @@
341344
files = (
342345
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
343346
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
347+
AECB905824658DC600ED1B83 /* sample.mp3 in Resources */,
344348
);
345349
runOnlyForDeploymentPostprocessing = 0;
346350
};

example/ios/sample.mp3

50.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)