Why doesn't my UILocalNotification play any sound?

主宰稳场 提交于 2019-11-30 21:59:42

If your application is in the foreground when the notification fires, no sound is played automatically. It will only play the sound automatically if your app is in the background at the time.

Your screenshot looks like your application might have been active in the foreground at the time you tried it.

According to Apple's push notification docs:

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

You can always play the sound yourself using the AudioServicesPlaySystemSound() method if you want to.

UINotification doesn't play sound if the app is Active because it doesn't make sense, it assumes that you see the notification if the app is Active, but it will play sound if the app is not running or, in Background to notify user that a notification has come.

Cheers.

You have to use *.caf format. I spent a lot of time but i found solution. I tried *.mp3 *.wav but doesn't work.

I hope it works.

How can i convert to *.caf format?

1) Open terminal

2) Example:

cd /Users/username/Desktop/FolderName

Click Enter

3)

afconvert -f caff -d LEI16@22050 -c 1 BlaBla.mp3 BlaBlaNew.caf

Click Enter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!