Hi, I'm relatively new to iOS development and kindly ask for some feedback on a strategy to achieve this desired behavior in my app.
My Question:
What would be the best strategy for sound effect playback when an app is in the background with precise timing? Is this even possible?
Context:
I created a basic countdown timer app (targeting iOS 17 with Swift/SwiftUI.). Countdown sessions can last up to 30-60 mins. When the timer is started it progresses through a series of sub-intervals and plays a short sound for each one. I used AVAudioPlayer and everything works fine when the app is in the foreground. I'm considering switching to AVAudioEngine b/c precise timing is very important and the AIs tell me this would have better precision.
I'm already setting "App plays audio or streams audio/video using AirPlay" in my Plist, and have configured:
AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .mixWithOthers)
Curiously, when testing on my iPhone 13 mini, sounds sometimes still play when the app is in the background, but not always.
What I've considered:
Background Tasks: Would they make any sense for this use-case? Seems like not if the allowed time is short & limited by the system.
Pre-scheduling all Sounds: Not sure this would even work and seems like a lot of memory would be needed (could be hundreds of intervals).
ActivityKit Alerts: works but with a ~50ms delay which is too long for my purposes.
Pre-Render all SFX to 1 large audio file: Seems like a lot of work and processing time and probably not worth it. I hope there's a better solution.
I'd really appreciate any feedback.
Post
Replies
Boosts
Views
Activity
On iOS 18.0+ simulators, tap any share link button from any app, select "Save to Files", the "Save" button is disabled.
In all previous simulator versions this works. This behavior even happens with default Apple apps like Photos.
Simulator: Version 16.0 (1037)
XCode: Version 16.1 beta (16B5001e)
macOS: 14.6.1 (23G93)
What is current best-practice for supporting an external display in a SwiftUI iOS app in 2024?
(I'm only interested in iOS 17 and/or iOS 18)
The only docs I found require abandoning the SwiftUI App structure and "switching back to a full UIKit App Delegate".
Is this still the only option?
Are there any complete examples on how to accomplish this?
Also is testing external displays with Simulator at all reliable? All experiences I read about say that it never works.
Thanks in advance.