Flutter: Phone call and background audio management - ios

In my Flutter project I added the function that when you receive a phone call the app’s audio music pauses, and when the call ends, it resume.
When the app is not in the background there are no problems in both iOS and Android. When the app is in the background when the call comes some problem occurs then.
With Android this also works when the app is in the background (before the phone call arrives), but with iOS I can't automatically restart it.
Even using didChangeAppLifecycleState with iOS when it is paused it is not possible to restart the audio (to my knowledge).
In Android, however, when it is in the background (always before the phone call arrives) it restarts, but I can't pause it so that when the phone call ends it restarts from the exact point where it stopped.
I thought that through “audio_system", you can control the audio in the background.
So, I ask you if there is the possibility to control the audio even in the background so that it can restart it with iOS or pause it with Android. I hope I was clear.
The problem for iOS is that I can't find a way to make it react when it's in paused mode. setState does not work and so do other commands. It's like hibernated.

Related

how to check what is killing my audio amplifier app? (ios, objective C)

I have an ios app that takes audio from the phone microphone, performs some processing on the mic data in real time and sends the result to headphones
In Project -> Capabilities -> Background modes, I have selected Audio, AirPlay and Picture in Picture
I want the app to continue to read microphone data and send audio to headphones when the app is in background (user presses home button) and when the phone screen is locked using the lock button
All of this is happening, so I don't think there are any problems with the app permissions, but I have noticed that after the app is backgrounded, it suddenly gets killed, usually in less than a minute
I managed to catch an instance of the app getting killed in the background in the xcode console and the message was
Message from Debugger: terminated due to signal 9
Looking around in google indicates that this simply means that the app was destroyed by the OS using SIGKILL
Is there any way to find out why the app was killed? Is it just impossible to keep the app running in background for a long period? Before I enabled Audio, AirPlay and Picture in Picture background mode, the audio used to stop as soon as I pressed the home button or the screen lock button. I am assuming that since the audio keeps running when I press the home button now implies I am indeed able to run mic/speaker in the background if I have to, and there are music players as well as audio recorder apps that work in the background until the user specifically closes them.
How can I find out the exact reason why my app is getting closed automatically, and what can I do to keep it running in the background indefinitely until the user closes it?
After you installed your app through xcode, run it normally (not by run in xcode), Let it crash. Then connect the phone, go to xcode -> Window -> Devices and Simulators -> View Device Logs. Then find the most recent crash.
Your particular problems sounds to me like overuse of CPU. App in background cannot utilize more than 80% (IIRC) of device CPU for extended periods of time (around one minute) or it will be killed by the system. If that is your case you simply need to optimize your code to not hog the CPU.

Background recording and server upload

I have an iOS app that is communicating with a bluetooth peripheral. When you tap a button on the peripheral, the app should start recording, whether it's in background or foreground.
Furthermore, there will be multiple recordings, in order to send them quickly to the server. So the app will record in chunks and then send them to the Parse database that I set up.
The chunk recording and uploading parts are working fine, but I have problems while the whole process starts in background, due to the bluetooth notification. The code that starts the recording is executed, but the completion block of the upload process is not. Maybe the recording starts but never finishes because the system stops the execution, since the app is in background?
I added the audio background mode so the app will be able to record in background, and I also added the voip background mode, since I read it will enable background network activity (which is something that I need in this case).
Unfortunately this didn't work.
Any suggestions will be appreciated.

IOS App and Background

I have a music signal processor app I want to publish and it needs to run in the back ground. I used to Info-plist to do so with UIBackgroundModes. It runs on IOS7 or less, and the problem I am having is once the phone locks and the app goes into the background I can't get it to come out of the background and its keeps running with the red banner at the top. Some of this I have learned as I go, but I have noticed some run on a timer, but I want mine, since its a music processor to keep going until the phone either unlocks or whatever interrupted it stops.
The app is basically a stomp box used with iRig. If that helps.
Thanks
Can you clarify about what you mean when the phone locks, the app goes into the background and yo can't get it to come out of the background? Are you saying like the app is playing music while the app is locked?

ios background app is slow to respond from MPNowPlayingInfoCenter

I created a music app that is wired up to MPNowPlayingInfoCenter. I have a bunch of methods that do various things (next, pause, etc). However, when I hit the next button in MPNowPlayingInfoCenter, the app responds immediately and calls the method instantly when the app is active. However, when the app is playing the background and I hit next from MPNowPlayingInfoCenter, it responds but after a few seconds.
Has anyone else experienced this or have any idea what the culprit might be here?
You shouldn't use any graphics code from the background - iOS will kill your app if you do so too much as it takes away from the resources available to foreground apps. It'll also cripple your other background routines.

Keep app running while iOS device locked?

I have an app that makes heavy use of video out. In a typical use-case, I'll have an iPad connected to an external monitor. I just want the external monitor on; the iPad display does not need to stay on.
The ideal case would be for someone to connect to an external monitor, then lock their iPad. But that pauses my app. (Currently, I'm calling setIdleTimerDisabled to keep the iPad from locking up and pausing my app.)
I'd like to give the user the option of locking the iPad, but still having my app running and sending images to video out. (Note: I'm not talking about keeping my app running when it's not in the foreground. I just want to keep it running while it's in the foreground, but the device is locked.)
Is this possible?
I would say no, it is not possible. Here's why:
The docs read:
Pressing the Sleep/Wake button is another type of interruption that causes your app to be deactivated temporarily. When the user presses this button, the system disables touch events, moves the app to the background but sets the value of the app’s applicationState property to UIApplicationStateInactive (as opposed to UIApplicationStateBackground), and finally locks the screen.
Something interesting to note in the docs above is that a bit further down under "What to do when an interruption occurs" Apple recommends that you stop doing certain tasks.
In response to this change, your app should do the following in its applicationWillResignActive: method:
Stop timers and other periodic tasks.
Stop any running metadata queries.
Do not initiate any new tasks.
Pause movie playback (except when playing back over AirPlay).
Enter into a pause state if your app is a game.
Throttle back OpenGL ES frame rates.
Suspend any dispatch queues or operation queues executing non-critical code. (You can continue processing network requests and other time-sensitive background tasks while inactive.)
This tells me that Apple doesn't want or expect your app to be doing much of anything in this state, other than preparing to be fully backgrounded.
On a related note here's a thread that shows how to determine whether you've hit the Sleep/Wake button or not:
Is it possible to distinguish between locking the device and sending an app to background?

Resources