0
votes

I have fire alarm application. During app is terminated state, a remote push notification with a custom sound "fire.wav" is received, the app will play the sound. After some time the alarm clearing notification with "default" sound is received. I need to stop the custom sound when the second notification received.

Also if the second notification didn't receive, i need to repeat the custom sound like a loop. The audio which i saved in bundle has 22 sec length. Please respond if anyone have this issue?

2

2 Answers

0
votes

As mentioned in the document here:

You can package the audio data in an aiff, wav, or caf file. Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead.

The only thing you can do is keep sending a notification in the 27-second interval until you you send stop sound notification. Even that doesn't guaranty an uninterrupted sound because of notification delay. Also, I will not suggest using PushKit in your case as it is mainly used for VOIP notification.

Now to stop sound on second notification have a silent notification on your bundle and inside your payload of the second notification set that as a sound file to play.

...
“aps” : {
   “badge” : 9
   “sound” : “nosound.aiff”
}, 
...  

That way soon the second notification arrives system will try to play a silent sound which should (haven't tried it so please check and update if it works) overwrite previous sound. make sure that you send nosound.aiff as without that system will play default sound.

0
votes

Here is my experience.

  1. Suggest to use Notification extension.
  2. When your app is terminated state, Apple allow the notification to wake your app up to do something less than 30sec.

And try to answer your questions: 1. You can play an audio less than 30sec. 2. You can stop that audio when receive second notification. 3. Can you play an audio repeatedly? Not sure, probably not, because more than 30sec, OS will close it.

And here is what you want to know, how to stop audio: Use Notification extension. This extension is a kind of process. You can play/stop the audio in it.