How do I get my sound to play when a remote notification is received?

后端 未结 2 593
天涯浪人
天涯浪人 2021-01-03 06:50

I\'m trying to automatically play a sound file (that is not part of my app bundle and is not a notification sound) upon receiving a remote notification. I want this to happe

2条回答
  •  甜味超标
    2021-01-03 07:24

    You cannot activate your audio session in the background, and you cannot initiate sound playback in the background. Background audio simply means that you can keep playing at the time your app goes into the background; but once your background sound has been interrupted, or if your app wasn't playing when you went into the background, you have no ability to make a sound.

    And this makes sense, because it would be terrible if apps the user isn't using, and may not even be aware of, could start making noise from out of nowhere.

    The usual thing is either to come to the foreground or to hand the system an immediate local notification that has a sound.

提交回复
热议问题