How to play UILocalNotification sound while do not disturb mode is on? - ios

I can't seem to find a way to play the local notif sound when do not disturb is on, it's for an alarm clock app so it's kind of essential that the sound play even when do not disturb is on. Is there anyway around this?
As another option I've considered having a blank audio play in the background until I need the alarm called, but I've heard that Apple would reject this method.

Why would you need to play when the phone is in do not disturb mode? Chances are that if the user wanted to hear the alarm they would disable the do not disturb mode. I don't think there is a way to get around your problem.

Related

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!

Swift AudioServicesPlaySystemSound playing even if phone is set to silent?

So i have created a roulette app, once the user lands it plays a sound. The problem is that the AudioServicesPlaySystemSound plays even when silent mode is on. Other sounds used acknowledge if silent mode is on, so i am a little confused on why this would be going on.
This code is being called every time the animation gets triggered to land the user on a mark.
code:
AudioServicesPlaySystemSound(self.systemSoundID)
Any idea what i can do to make it work with silent mode for all sounds?
Once i switched too
AudioServicesPlayAlarmSound
Im assuming it acts as if the sound is an alarm, and if silent mode is on it wont play whereas the other method plays regardless

ios setting to neatly bypass iphone mute

I am working on an app that, among other things, provides alarms in emergencies. I would like to add a setting that will allow users to receive alarms with sound even if their phone is muted. As far as I am aware, this could be hacked by playing an mp3 through media services, as if the app was a music player left to play in the background, but that doesn't seem extremely kosher.
Does anyone know a 'neater' way to do this? Can I somehow allow my users to prioritise my app over the mute button?
Thank you very much.

Using the TTS Synthesizer in iOS when the app is ALREADY on the background

I would like to play a sound and use the AVSpeechSynthesizer to speak out some strings. The point is that I want these to happen when the device is already locked and then some events happen which triggers them.
I've found lots of info about how to play sound on the background, but this means that playback starts when the app is active and then the playback could continue, if the screen is being locked (after the start of playback). I've done all the tricks but can't hear a sound, which is triggered when the device is locked (and app is already on the background). However this works with iOS 8.3 simulator almost out-of-the-box, but not with a device.
So how to resolve this? Should I actually use some notification stuff to produce the desired outcome? I'm not too familiar with the notifications, so is there any other workarounds or is the notifications way easier than I think?
Cheers,
Mikko

Pause / Play background audio from other apps

I know this is likely way outside of the sandbox but I thought I'd ask anyway:
I want to put a "pause / play" button in my app that will pause or play any background audio. Basically I'm looking to implement the play/pause button found in the multi-task bar.
A simple example is someone stars music with Pandora app, then launches my app. Is it possible to pause the background audio and resume it?
As a curiosity I have wondered if there was a way to create or broadcast the "remote control" events. Can I publish a pause/play event to the OS, perhaps?
I think here's what you're looking for. The trick is to loop a short audio file with silence when you want the other audio to stop. Then tell the iOS audio system when you're done, as suggested in the link.

Resources