I’ve rewritten the audio player for the iPhone app that I developed 4 times before settling on the current implementation. Playing audio with Swift has many working examples to choose from and at the most basic level is easy even for me to implement. But streaming and caching audio was a bit outside of my range of capabilities at the time, so I used an open source library to fill the requirements.
Unfortunately, the framework I am relying upon does not allow for repeating audio if the screen of the device goes to sleep. A rather serious limitation as far as the user is concerned.
I’ve been sitting on this bug for over a month and today I, after doing all the possible household chores imaginable, decided to sit down and once again to try and attempt a fix. Unfortunately no easy fix was forthcoming, except this rather inelegant hack:
UIApplication.shared.isIdleTimerDisabled = true
This essentially prevents the screen from dimming and going to sleep. That solves the problem, and would be fine if this was an alarm clock app., but not fine when you are trying the escape the glow of a device in the bedroom.
This method also breaks down if the app for some reason is placed in the background, which will require a whole other set of digging for answers.