{"_id":"561c65e0bc063c0d00aec192","category":{"_id":"589b8e1fdbb7cd190026732c","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"version":"55e67aab9cc7c62b00c4a1ed","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"project":"55e67aaa9cc7c62b00c4a1ea","user":"55d29988486de50d00327118","version":{"_id":"55e67aab9cc7c62b00c4a1ed","project":"55e67aaa9cc7c62b00c4a1ea","__v":10,"createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["55e67aac9cc7c62b00c4a1ee","55e67b5556007d23005fee7d","55e67b5dde6fef23009480ca","55e680efde6fef23009480db","55e6829485a9741900314e99","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","589b8e1fdbb7cd190026732c","58b8ca5e3265d70f001788d4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":5,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-13T02:01:04.414Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"Custom sounds can be a great way to make your application stand out. When you don't customise sounds, your app uses the system setting for receiving an SMS. In some cases, this may cause the user to either disable sound, disable push or uninstall your application. Having a unique and entertaining sound appropriate for your context is a great way to keep users engaged. This article will help you implement custom sounds on iOS and Android with Carnival. \n\n\n\n## On iOS\n\n### Default sound\nFor a default sound, use the key `default` in the Carnival dashboard or via the API as the `sound` key. \n\n### Vibration\nWhether the sound plays or a vibration occurs is a device level setting controlled by the user. This is set in the user's settings.  You cannot specify that a vibration should occur with a special push payload. If you want a vibrate you occur every time, the suggested technique is to programmatically vibrate the phone when a push arrives, but this is still subject to user settings.\n\n\n### Custom Sounds\nFor iOS, you need to include the right type of file in your app bundle, which [Preparing Custom Alert Sounds](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6) covers in detail. If the audio file doesn’t exist or default is specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds.\n\n\n\n\n## On Android\n\nLike on iOS, Android uses a packaged sound for custom sounds. You should simply put the audio file under res/raw folder of your project. If the sound can't be found, the default will be played. \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"See [Supported Media Formats](https://developer.android.com/guide/appendix/media-formats.html) on the Android docs for details on what audio file formats are supported on Android devices.\"\n}\n[/block]\n## Publishing\n\nWhen it comes time to publish your message, simply enter the file name in the message compose screen. For example, if you're sending a photo of a cat in an image type message, you might want to send a custom sound that sounds like a cat purring. \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"On Android, the filename entered in the sound field must not contain the file extension.\"\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/2fc3df4-image_13.png\",\n        \"image_13.png\",\n        570,\n        280,\n        \"#e5edf3\"\n      ]\n    }\n  ]\n}\n[/block]\n## Optimizing for both platforms\n\nA common file type between both Android and iOS is a linear PCM Wave file with a .wav extension. You can then generate the audio file once from your audio software and use for both applications.","excerpt":"Play a custom alert sound when the user receives a push","slug":"custom-alert-sounds","type":"basic","title":"Custom Alert Sounds"}

Custom Alert Sounds

Play a custom alert sound when the user receives a push

Custom sounds can be a great way to make your application stand out. When you don't customise sounds, your app uses the system setting for receiving an SMS. In some cases, this may cause the user to either disable sound, disable push or uninstall your application. Having a unique and entertaining sound appropriate for your context is a great way to keep users engaged. This article will help you implement custom sounds on iOS and Android with Carnival. ## On iOS ### Default sound For a default sound, use the key `default` in the Carnival dashboard or via the API as the `sound` key. ### Vibration Whether the sound plays or a vibration occurs is a device level setting controlled by the user. This is set in the user's settings. You cannot specify that a vibration should occur with a special push payload. If you want a vibrate you occur every time, the suggested technique is to programmatically vibrate the phone when a push arrives, but this is still subject to user settings. ### Custom Sounds For iOS, you need to include the right type of file in your app bundle, which [Preparing Custom Alert Sounds](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6) covers in detail. If the audio file doesn’t exist or default is specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds. ## On Android Like on iOS, Android uses a packaged sound for custom sounds. You should simply put the audio file under res/raw folder of your project. If the sound can't be found, the default will be played. [block:callout] { "type": "info", "body": "See [Supported Media Formats](https://developer.android.com/guide/appendix/media-formats.html) on the Android docs for details on what audio file formats are supported on Android devices." } [/block] ## Publishing When it comes time to publish your message, simply enter the file name in the message compose screen. For example, if you're sending a photo of a cat in an image type message, you might want to send a custom sound that sounds like a cat purring. [block:callout] { "type": "warning", "body": "On Android, the filename entered in the sound field must not contain the file extension." } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/2fc3df4-image_13.png", "image_13.png", 570, 280, "#e5edf3" ] } ] } [/block] ## Optimizing for both platforms A common file type between both Android and iOS is a linear PCM Wave file with a .wav extension. You can then generate the audio file once from your audio software and use for both applications.