Why doesn't my UILocalNotification play any sound?

后端 未结 3 1197
时光说笑
时光说笑 2021-01-06 09:09

This is driving me nuts, I believe I have tried every possible approach by now, but my phone still decides to stay silent. I just want it to play any sound for now

相关标签:
3条回答
  • 2021-01-06 09:36

    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.

    0 讨论(0)
  • 2021-01-06 09:36

    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

    0 讨论(0)
  • 2021-01-06 09:43

    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.

    0 讨论(0)
提交回复
热议问题