How to get only Alert tones of device (not all the device sounds) and select one of them as my app notification.
I've gone through Apple documentation which states that we cannot use System Sounds for our app.But, in WhatsApp you can see this feature.
Please help me out to solve this issue.
The aps dictionary contains a property that specify a sound to play:
{
"aps" : {
"alert" : "You got a push.",
"badge" : 9,
"sound" : "bingbong.aiff" //here
}
}
You have to embed the sound file in your app, if you like the systems sounds, then try to make your own.
Documentation
The name of a sound file in the application bundle. The sound in this
file is played as an alert. If the sound 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; see “Preparing Custom Alert Sounds” for details.
Note: You Not put Alert Notification sound means Its default Take System(iPhone or iPad) Message Tone.
You can't get List of Tones from iPhone.Apple not allowed this. WhatsApp may be used for copy the tones and add their resource file.
Reference:
Access apple's iOS ringtones and display them
Related
I am successfully modifying my remote notification payload using the UINotificationServiceExtension.
I want to change the alert sound based on the user's choice here. In order to do that I need to assign a UINotificationSound object to the bestAttemptContent:
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "alertTone.caf"))
This will work for tones which I have created and imported into my project. One named alertTone.caf in the above example.
However, I want to use the system alert tones instead of my own. I know I can set the default tone but I want access to other custom tones. Is there anyway at all to do this?
You can't reference the system sounds for UNNotificationSound, but you can try to play the sound when you receive the notification in the service extension.
// import
import AVFoundation
// create a sound ID, in this case its the tweet sound.
let systemSoundID: SystemSoundID = 1016
// Play the correct sound when the notification is received in the service extension
AudioServicesPlaySystemSound (systemSoundID)
Source for playing system sounds here.
This is a list of all the system sound ids that you can use for reference.
I am using a UNNotificationService extension to update the Payload content of a received Push Notification.
I'm able to change the displayed alert text and the updated text is correctly displayed. However changing
"sound":"default" => "sound":"something.caf"
does not play the modified sound. The default alert sound is played.
The audio file "something.caf" is packaged with the App and plays correctly when the Payload received from the backend server contains "sound": "something.caf".
Any suggestion to what I should be looking at? (missing configuration etc)
Thanks
Is the sound file added to your Notification Service ?
You can verify this on inspector tab -> Target Membership section
Setting the "UNMutableNotificationContent.sound" property to the required sound file fixes the issues and plays the required file.
How can I repeat sound file when PN(push-notification) arrive in my device using Objective- c.
You can find how to Custom Alert Sounds in this website: Managing Your App’s Notification Support and the ringtone can not be Over 30s
Preparing Custom Alert Sounds
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. The sound files must be in the main bundle of the client app.
Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.
You may use the afconvert tool to convert sounds. For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu.
Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
You can make this example dictionary send to APNs server with your custom alert sound name for the value of 'sound':
// Create the payload body
$body['aps'] = array(
'alert' => 'TestNotification',
'sound' => 'YourCustomAlertSoundName.caf',
'badge' => 8
After making a good ringtone to your project's main bundle, the important step is to add the sound file you added (YourCustomAlertSoundName.caf) to Build Phases-> Copy Bundle Resources in the Project Settings, and the ringtone can not be Over 30s, otherwise the system will enable the default ringtone (default).
You just have to set custom file into sound on push payload. Put the same audio file into your build resource and just fire notification from server, it will play audio.
{
"aps" :
{
"alert" : "This is your alert text"
"sound" : "YOUR_COSTOM_FILE_NAME.mp4"
},
}
When the application is in foreground mode, then you need to play same audio file when you get receive notification.
I need to customize push notification sound. I don't want to create and include to Bundle. I need to implement like whatsapp notification sounds or please give a list of Apple provided sounds(like default sound). Any help would be highly appreciated.
Thanks
After digging this issue for more than 3 weeks, and writing back and forth with apple this is the only solution
change payload to something like
sound = "custom"
now you need to show all your system sounds in a table view (if you don't know how to do it, look on github).
once the user mark his sound notification you need to copy the file to library/sound and give it the name of custom (or whatever the exact name in the payload).
that way you never change the server side code and you keep it on custom, and on the other hand you just overwrite the custom file with a new sound the user has been chosen.
*SIDE NOTE: on version 9.2.1 there's a bug which cause the notification not to work on the second time, or at all, it's should be fixed according to Apple in the next version 9.3 !
in the breath I wish the solution I could override the payload like we can do in Android, Apple makes push notification a lot harder on the developers.
in you bundle add a sound file named "pushSound.caf".
//write your payload this way
{
aps =
{
alert = "message";
sound = "pushSound.caf";//this file will have to your bundle
};
}
Preparing Custom Alert Sounds
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. The sound files can be in the main bundle of the client app or in the Library/Sounds folder of the app’s data container.
Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle or to the Library/Sounds folder of your data container.
You can use the afconvert tool to convert sounds. For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu.
Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
It needs to be in the correct format as well, see https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6
To use the default sound for a notification
let content = UNMutableNotificationContent()
/// Set up content ...
content.sound = UNNotificationSound.default()
To use a custom sound, the sound file has to be stored in the app's main bundle OR download it and store it in the Library/Sounds subdirectory of the app's container directory.
The "main bundle" approach can only be used with a new application release, the "downloading the sound file" approach is more flexible and makes shipping new sounds without a new version release.
I send a parse push notification which the app receives, but the sound requested does not play, instead the default sound plays. The sounds have been saved by the app in the documents folder. I can check in iTunes that they are there. At some point this was working, but for some reason it has stopped playing the requested sounds. If I log the push notification user info dictionary the sound name is correctly there:
2015-01-11 12:17:41.356 My App[239:60b] didReceiveRemoteNotification, userInfo: {
aps = {
alert = "XXX says FOO from the console!";
sound = "w8nmridutW_v1.mp3";
};
}
Any ideas?
It is possible that the audio format that you use is not supported. Was it a different file when it was working ?
Check with the apple documentation.
According to the documentation here, mp3 isn't a supported file type. Are you sure you were getting this mp3 file to play before? If so, you were experiencing undocumented/unsupported behavior.
Here's the pertinent bit:
Preparing Custom Alert Sounds
For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. The sound files must be in the main bundle of the client app.
Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.
You may use the afconvert tool to convert sounds. For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app:
afconvert
/System/Library/Sounds/Submarine.aiff
~/Desktop/sub.caf -d ima4 -f caff -v
You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu.
Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.