Disabling microphone programmatically - ios

I wonder if there is any way to disable microphone programmatically (to get rid of the red bar in the background)?
I use OpenEars to listen for commands in the app. When I go to the background red bar appears (which is obvious, as microphone is active).
The problem is that the microphone is active even when OpenEars is suspended. To avoid unnecessary questions I cannot stop OpenEars as it ends up with mixing audioSession with my other sources.

The "red bar" will never disappear, even when the microphone is not in use by your application unless you explicitly stop the audio session. This is a security measure Apple has put in place to alert users of your application that it is listening to their microphone, even if you aren't doing anything with the microphone data at that exact moment.
If you are using AUAudioUnit, you may have some luck setting isInputEnabled to false.

I'm not sure if it falls into stopping OpenEars case per se, but have you tried switching AudioSessionCategory when your app goes into background/suspended mode? If you switch to a category that doesn't allow microphone input, my guess is it would stop the microphone.
Then you could reset to the correct category when your app resumes.

Related

Turning off audio background mode triggers kMIDINotPermitted even though background audio is not needed

I've got a MIDISampler that is triggered by a MIDICallbackInstrument. I don't want my app to work in the background since it is an interactive ear training game. Unfortunately if I disable "Audio, AirPlay, and Picture in Picture" I get the following error:
CheckError.swift:CheckError(_:):176:kMIDINotPermitted: Have you enabled the audio background mode in your ios app?
Also the sampler plays fixed pitch sine waves instead of samples.
The solution would be to just turn on the audio background mode though it is not needed. Everything works fine, no errors. Unfortunately Apple is rejecting my app in that case since it's not using background audio.
Does anyone know a work around for this?
You need background audio enabled for MIDISampler. As long as your app is stopping the audio engine when the app moves into the background, they should allow it. I would explain your use case and appeal the rejection.

Record Audio Whilst Device is Locked iOS

Does anyone know of an effective way to record audio whilst the device is locked on iOS?
Currently I am using two AVAudioRecorders, one to listen out for noises (audioListener) and one to actually record those noises (audioRecorder). The audioListener is always recording and getting the meter levels of the noises as it needs to be recording in order to get those levels. If those noises go above a threshold then the audioRecorder starts recording for five seconds and in the audioRecorderDidFinishRecording method will add each audio file to an array for reference later. I have also already set the "Application does not run in background" key in the info.plist to NO and allowed the audio background mode.
I still need to do a few more tests to see if it records correctly when the device is locked but was wondering anyone knew of any other ways of accomplishing this?
You need to set the audio category to AVAudioSessionCategoryPlayAndRecord as well as the background audio mode as you have done.
Check out the AudioSession Programming Guide

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

AVAudioRecorder and AirPlay Mirrioring

When I have an AVAudioRecorder Session active - (when I'm recording audio) I can't activate AirPlay mirroring on the device. Airplay mirroring just deactivates while the app is running and switches it back on when the app exits. This post seems to suggest there is no way around this.
My thoughts are to try:
using a lower level recording framework
or outputting a separate window to external display, rather than mirroring (I've tried this, it doesn't work).
Is there another way around this, or do you know whether either of these methods are known to work?
Using AudioQueue to record (like Apple's Sample Code Speak Here) rather than the AVRecorder works. A bit more work to implement, but recording continues on or off Airplay mirroring.

How to make an app to play ringer with behaviors similar to iphone native phone ring

I am working on a VOIP app on iOS. I have encountered some problems when implementing "Ignore incoming ringer" feature. It has the following requirements:
1. Should stop ringer if pressed screen lock or volume button
2. Should stop ringer if mute button is pushed to "mute" state
3. Should not play ringer if mute button is in "mute" state
Since iOS SDK provide no information of the phone's hardware buttons, I can only rely on setting AVAudioSession category. Before playing ringer, I set the category to ambient so screen lock and mute button can stop the audio. But this method cannot satisfy my requirements because app cannot play ringer when in background because ambient category cannot support background audio.
In order to solve this problem, I start playing the ringer in playbackandrecord category to make the audio stream come out and change the category to ambient immediately. Though it can meet my requirements, but this method caused many problems and bugs. For exameple, MPVolumeView cannot display the output devices correctly.
Can anyone provide a more elegant way way to simulate ringer? Or can this be done in iPhone? Since it will be in app store, I cannot use private apis. Thanks in advance.

Resources