Play system sound on push notification - ios

I display the list of sound retrieved from "/System/Library/Audio/UISounds".When user select any sound, I send the name of sound to the server. When server send the push notification , it configure that name in payload ,
But still iOS play the default sound. What Do I have to do to play the selected sound.

it is possible in local notification. will attached in the payload, key ="sound"
aps =
{
alert = "test example notification message";
sound = "example.caf";
};
example.caf file import in your xcode project.
you will try the same concept may be it will works.

Related

How to customise push notification sound in iOS?

I am making a chat app. The user can select the notification sound for a particular chat/group. When the app is in the killed state, if a new message arrives I want to play the sound that the user had selected for that chat otherwise play default sound. How can I do this?
App bundle must have your all sounds file
User selected sound name and feedback to you app server
Your APN server get the selected sound and push notification with the sound name

Stop to play Push Notification sound as I receive PushNotification Payload, (or When DidreceiveNotification method of App Delegate is Called)

I am new in iOS development, and I am working on an iOS app in which some options are available for user to get pushNotification, such as users can select "Do not Disturb", "AnyTime" "time b/w"...something like this. So If user choose "Do not Disturb" then I do not have to play sound and alert. So please give me solution of that.Is this possible or not in iOS App development. Please tell me.
Thanks in advance...
If you don't require sound for the push notification, Don't give sound object in push payload.
If the user has chosen "Do not Disturb", indicate the server sending push notification to remove sound from the payload.
{
"aps":{"alert":"Hello","category":"your_category_key"}
}
Other wise include sound.
{
"aps":{"alert":"Hello","sound":"default","category":"your_category_key"}
}

can we add a custom sound for notification in iOS apps, other then the default sound provided by the OS

We have a scenario where we need to play a custom notification sound for an app which is different than the notification sounds provided by OS. Is it possible can we add a different sound other than the OS sounds to the app and also do we have any problem while app review if we use such sounds in the app.
Thanks.
Yes, You can change the push notification sound.
When server sends the push notification, just add the sound file name in JSONpayload.
Sample Push Payload:
{
"aps" : {
"alert" : "Your friend needs your help.",
"sound" : "sos.wav"
}
}

Firebase push notifications custom sound

I am currently working on an app and I have implement firebase Push Notification service into my app. I am recieving notification on my iphone but I am unable to set the custom alert sound that I want.
I added the sound as a .caf
I added the sound to the Copy Bundle Resources
using print (userInfo) I have collected this data that is incomming from Firebase
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
I understand where the problem is, I just dont understand how to fix it so that the app plays my custom notification sound.
Problem with Firebase is that you can not send sound parameter like custom parameter with Firebase Console, if you try this as you do, you will get this parameter in app outside of aps Dictionary and the system will not recognize it as a sound to be played although the sound file is into the project.
The only solution for this problem is you have some API/server through which you'll be sent a Firebase notification. When server send you a notification with sound param it will be within aps Dictionary and application will play this sound when the notification arrives.
After much research I have not found any solution.
Under Firebase Messaging Docs, and
Table 2a. iOS — keys for notification messages
it is indicated that Firebase does allow for the Sound key to be included in the payload but as seen in the code printed by didRecieveRemoteNotification,
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
Firebase doesn't include the Sound key inside the aps hence not calling the sound key by the app.
The workaround that I used for my app is Easy APNs Provider which is a handy and easy app to use for development purposes, a major issue is that it doesn't have the ability to register and remove notifications automatically.
lastly: for Push Notifications to my published apps, I have opted for a dedicated server which I run off of my website
It's been over 5 years, but if someone still looking for an answer, here is what I did.
Make sure you have configured Firebase Messaging & receiving Notifications.
Add .caf ( sound file ) to the app. It must be visible on
'Target' - > 'Build Phases' & then under 'Copy Bundle Resources'
Delete the app from the device ( This is important )
I use Postman as my server, so message format would be,
{
"notification": {
"title": "Hello",
"sound":"small_message.caf",
"body": "You have a new Job"
},
"to": "your device token"
}

iOS8.2 not playing custom alert sound from parse.com app

I have successfully set up a push notification app via Parse.com. App is installed on iPhone 5s running iOS8.2. App code in Swift
If I send a regular push notification, it comes up fine, but plays the very short buzz (like 'quick' vibration or very short standard 'note' text alert, rather than what I have set as the standard text alert.
(If I send an iMessage, and have the alert tone set to 'chord', it plays that OK)
If I instead send the dictionary version with a custom sound included in the app bundle (yes, I converted it in terminal per Apple instructions), it still does the same as above. I cannot get it to play any custom alert sounds.
It makes no difference if I originate the push from the app, or from the button on Parse.com
Just as the other person said, ensure that your file is in the correct format (you want it in an generally .caf files)
Also, be sure that you have entered the correct file name when you are sending the push notification if you are using client push.
Example from Parse Docs:
let data = [
"alert" : "The Mets scored! The game is now tied 1-1!",
"badge" : "Increment",
"sounds" : "cheering.caf" //Ensure the file exists in your project
]
let push = PFPush()
push.setChannels(["Mets"])
push.setData(data)
push.sendPushInBackground()

Resources