Custom Sound for Notifications

Custom Sound for Notifications

Overview

Custom notification sounds provide a unique, branded experience for your app users. You can add custom sounds to all notifications or specific types, such as important notifications like delivery status updates. This guide explains how to integrate custom sounds using OneSignal notifications for iOS, Android, Amazon, and Windows platforms.

Step-by-Step Instructions

Step 1: Create Sound Files

Ensure your sound files meet the following criteria:

  • Filename: Use lowercase letters and underscores (e.g., awesome_sound.wav).
  • File Format:
    • iOS: .wav, .aiff, .caf (must be Linear PCM, MA4, µLaw, or aLaw; less than 30 seconds).
    • Android and Amazon: .wav, .mp3, .ogg.
    • Windows: .wav, .mp3, .wma (must be less than 10 seconds).

Step 2: Add Sound Files to App

Include sound files as resources within your app. External URLs are not supported.

  • iOS:

    • Native: Add files to the Xcode project root, ensuring "Add to targets" is selected.
    • Cordova, Ionic: Add files to the Resources directory within the Xcode project.
    • Unity: Add sounds anywhere in your Unity project, then move them to the Xcode project root after building.
  • Android and Amazon:

    • Native: Add files to res/raw.
    • React Native: Add files to <project-root>/android/app/src/main/res/raw.
    • Cordova: Add files to <project-root>/platforms/android/res/raw/.
    • Ionic: Add files to /android/app/src/main/res/raw/.
    • Unity: Add files to Assets/Plugins/Android/OneSignalConfig/res/raw.
  • Flutter: Add files to main/res/raw.

  • .NET MAUI: Add files to <project-root>/Platforms/Android/Resources/raw/.

Step 3: Send Notifications With or Without Sounds

For Android & Amazon:

  • Notification Categories:
    • Go to Settings > Messaging > Android Notification Categories to create a group and channel.
    • Set Importance to "Urgent" or "High" to play sound.
    • Set Sound to "Default" or "Custom" (e.g., cat_meow_sound without file extension).

For iOS:

  • Reference the sound file with the extension (e.g., explode_sound.wav).
  • Set this in the Dashboard Push Messages or use the API ios_sound property.
  • For no sound, pass in nil to the Sound field.

Using REST API

Instead of using the dashboard, you can send notifications with sounds using the REST API with appropriate parameters:

  • iOS:

    • ios_sound (Include file extension; e.g., ios_sound: explode_sound.wav).
    • For no sound, pass nil.
  • Android:

    • android_channel_id (use if created in the OneSignal Dashboard Notification Categories).
    • existing_android_channel_id (use if created elsewhere).
  • Amazon:

    • adm_sound (Do not include file extension; e.g., adm_sound: explode_sound).

Additional Notes

  • Propagation Time: New sound resources may take a while to reach all users. Wait a few days before using new sounds in notifications to ensure users have updated their apps.
  • Debugging Sound Issues:
    • Ensure correct file extension and format.
    • Verify the sound file is in the correct location.
    • Check the file length (less than 30 seconds for iOS and 10 seconds for Windows).
    • If shrinking resources is enabled, protect sound files from being removed by creating keep.xml in res/raw/:
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@raw/sound_file"/>

FAQ

  1. Can I set a default sound?

    • OneSignal does not support default sounds directly. Use a template referencing the sound for every message you send.
  2. Why is my notification not playing the custom sound file?

    • Possible reasons include incorrect file extension, unsupported format, incorrect location, or the file is too long. Check OneSignal and platform documentation for more details.
  3. Why is my notification playing the default sound file?

    • Ensure the sound file is in the correct location and format, and that your setup instructions were followed correctly.
  4. Why is the wrong sound playing?

    • On Android, notifications grouped together will play a default sound. Set the sound with the GROUPKEY for all your notifications.

By following this guide, you can successfully integrate and customize notification sounds for your app, enhancing the user experience with unique and branded notifications.


media-icon
media-icon
media-icon
media-icon

2024 Orufy Technologies All Rights Reserved.