Skip to content

Commit

Permalink
Add an example with sound in project example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dallas62 committed May 8, 2020
1 parent 4899349 commit f2dd349
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
14 changes: 14 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,27 @@ export default class App extends Component {
}}>
<Text>Local Notification (now)</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.notif.localNotif('sample.mp3');
}}>
<Text>Local Notification with sound (now)</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.notif.scheduleNotif();
}}>
<Text>Schedule Notification in 30s</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.notif.scheduleNotif('sample.mp3');
}}>
<Text>Schedule Notification with sound in 30s</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
Expand Down
12 changes: 6 additions & 6 deletions example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class NotifService {
NotificationHandler.attachNotification(onNotification);
}

localNotif() {
localNotif(soundName) {
this.lastId++;
PushNotification.localNotification({
/* Android Only Properties */
Expand All @@ -35,14 +35,14 @@ export default class NotifService {
/* iOS and Android properties */
title: 'Local Notification', // (optional)
message: 'My Notification Message', // (required)
playSound: false, // (optional) default: true
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)
playSound: !!soundName, // (optional) default: true
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)
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
});
}

scheduleNotif() {
scheduleNotif(soundName) {
this.lastId++;
PushNotification.localNotificationSchedule({
date: new Date(Date.now() + 30 * 1000), // in 30 secs
Expand Down Expand Up @@ -70,8 +70,8 @@ export default class NotifService {
/* iOS and Android properties */
title: 'Scheduled Notification', // (optional)
message: 'My Notification Message', // (required)
playSound: true, // (optional) default: true
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)
playSound: !!soundName, // (optional) default: true
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)
});
}

Expand Down
Binary file added example/android/app/src/main/res/raw/sample.mp3
Binary file not shown.
4 changes: 4 additions & 0 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
4303B027D05E61B36AF2D9DA /* libPods-example-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D89C42625470FE853701396C /* libPods-example-tvOS.a */; };
4BF20923B09DA7D7C7D74054 /* libPods-example-exampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F3EFF15EA907A6500887787 /* libPods-example-exampleTests.a */; };
66172E2B135131DB9C88C137 /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 67C595176EF92CCFA00C1943 /* libPods-example.a */; };
AECB905824658DC600ED1B83 /* sample.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AECB905724658DC600ED1B83 /* sample.mp3 */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -62,6 +63,7 @@
67C595176EF92CCFA00C1943 /* libPods-example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
ACCB69D76B81B3D29BE3BB2B /* libPods-example-tvOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
AECB905724658DC600ED1B83 /* sample.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = sample.mp3; sourceTree = "<group>"; };
AED90B1C243E6D21006F11F7 /* example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = example.entitlements; path = example/example.entitlements; sourceTree = "<group>"; };
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>"; };
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>"; };
Expand Down Expand Up @@ -126,6 +128,7 @@
13B07FAE1A68108700A75B9A /* example */ = {
isa = PBXGroup;
children = (
AECB905724658DC600ED1B83 /* sample.mp3 */,
AED90B1C243E6D21006F11F7 /* example.entitlements */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
Expand Down Expand Up @@ -341,6 +344,7 @@
files = (
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
AECB905824658DC600ED1B83 /* sample.mp3 in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file added example/ios/sample.mp3
Binary file not shown.

0 comments on commit f2dd349

Please sign in to comment.