3
votes

I have to play notification sound in my app when someone calls the user. When I put app in minimised state, push notification get displayed with custom sound that I have assigned to it. But when my app is in foreground, same custom sound volume level does not follow ringer sound level. I have used audio services for playing sound when app is in foreground. But there is difference in volume levels of notification sound and same sound played by audio service.

2

2 Answers

0
votes

You are quite right, there is intended difference between those two. And here is the deal.. the sound level of a Remote notification is driven by the 'Ringer and Alerts' volume level. While on the other hand the in-app played audio is affected by 'Music and Audio' volume level.

Note: If you want to play the sound at the 'Ringer and Alert' volume level you could use AudioToolbox framework and play a System/Alert sound (but keep in mind that this will play only short sounds up to 30 seconds)

Here is the Apple Docs for it: https://developer.apple.com/library/prerelease/ios/documentation/AudioToolbox/Reference/SystemSoundServicesReference/index.html#//apple_ref/c/func/AudioServicesPlayAlertSound

0
votes

I have solved this, by using AudioServicesPlayAlertSound to play SystemSound. What I did wrong was the method which used to play SystemSound. There are two methods can be used to play SystemSound i.e AudioServicesPlaySystemSound and AudioServicesPlayAlertSound. I was using AudioServicesPlaySystemSound which does not follow volume level which is used by Remote Notification. So now I am using AudioServicesPlayAlertSound, which plays sound at same level as Remote Notification.