How to build iOS Swift Alarm App with background Task - ios

Im facing troubles with an app im working on.
I already have an android app that is running like that:
A background task i checking every 30 seconds an api to check if there is something going on my server.
When there is a result an alarm will come up and plays an mp3 and then shows an full screen activity with text and buttons.
The mp3 will be repeated for 5 minutes or when the user clicks on a button and replies to the alarm.
The mp3 is also played even if the pohone settings are on mute.
I also have an Setting inside the app where you can choose to mute the sound and only show the activity.
I need to have the same behaviour in my ios app but have no idea how to handle it in Swift.
The background task itself is also terminated after 30 seconds.

Related

AVAudioRecorder stops after certain time on background

I'm using AVAudioRecorder to record audio on my Swift app. It takes 30 seconds clip, do some things with that clip, deletes the clip and then it starts the recording of 30 seconds on a new clip, and it goes on. The app works fine doing that on the background, I have the audio background mode enabled. The problem that I'm having is that, when it passes some time (probably like 90 minutes or something like that), the recording suddenly stops and it does not continue recording. I handle the interruptions in my app fine, so when the recording stops for some reason, I get a notification telling me that the recording has been stopped; but when it passes about 90 minutes, the recording just stops without giving me any alerts or something.
In fact, I enable the recording with an UISwitch. If the recording stops normally due to some interruption, the switch changes to 'off'. But when the recording stops when about 90 minutes has passed, the switch does not change and it is like the app doesn't get notified about the recording session being canceled.
I do not know if this is due to some time restriction when I use a recording on the background or something like that. I could't find any documentation about this problem, so that's why I'm asking for help here.

AVAudioPlayer not playing after a while when app is in background

I am making an alarm clock app. To play the alarm sound at the appropriate time, I use myAudioPlayer.play(atTime: myAudioPlayer.deviceCurrentTime + secondsUntilAlarm). This way, even if the app is in the background, the audio player plays the alarm sound at the appropriate time.
Note: I got this idea from a different SO answer, which unfortunately I can't seem to find right now.
However, what I've noticed is that alarms are being played correctly if the secondUntilAlarm value is relatively soon, like maybe 20 minutes or less (converted to seconds of course since that's what the method requires). However, if it's longer than that, the sound does not play. Is there something I'm missing with how this method works in the background? Could the app be entering some sort of suspended state or something that disables the audio player from triggering the playback?
Any suggestions or comments would be appreciated--thanks!
So I've actually determined that it does not matter if the app enters the suspended state (in fact, this is expected). I've identified that the reason the alarm sound does not play sometimes because I open another app with audio that deactivates my app's audio session (therefore, it has nothing to do with the time the alarm is set for). To fix this, all I had to do was ensure I set .mixWithOthers for my app's audio session. That way, other audio sessions from other apps don't deactivate mine!

Play sound at a specific time in background iOS

I have a muslim app that triggers local notifications with sounds for prayer times throughout the day. The sounds are limited to 30 seconds. I am searching for a workaround to play sound longer than that.
I found out I can use AVAudioSession to play audio even if the app is in background by turning on Background Modes (Audio, Airplay, and Picture in Picture) in Capabilities target tab and using background task to play the audio. However I want to play sound at a specific time by scheduling it.
Among the workarounds I found are also setting continuous local notifications. However I came across an alarm app (Alarmy) that can play sound when local notification is received. How is that doable? Thank you in advance!

iOS audio background mode for short one time sounds

I want to create a feature in my app the makes a sound every 5 seconds. The sound file is short and in order to play it every 5 seconds i use a timer.
The issue is i want to play it even if the app is in the background for a maximum time of 30 min and could also be different bpm for each user. I have used background audio mode to do it but i could find in the documentation how does playing sounds is threated by the system i dont want my app to be suspended. I only saw referance to playing music songs in the background with a player.
How can i be certain i will receive the background time needed just for playing small sounds every few seconds and not playing continues music? I was thinking about empty sound wave file but afraid apple would reject my app.
Thanks for any help i can get.

Is it possible for timer running in iOS background?

I made a timer. After I hit home button in iOs simulator, it was still running in the background. I didn't save the state, I only added local notification. Why is that?
Also, I set to play a 4 seconds sound in notification and it came out that the sound only played 3 seconds. Is there a limitation of how long the sound can play for notification?
Maybe you selected one of them:

Resources