Background recording and server upload - ios

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.

Related

Flutter: Phone call and background audio management

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.

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.

ios play continues sound when app receive push notification

Currently i am working on app in which i want to play continues sound when app receives push notification. as i know apple allow to play custom sound of length of 30 sec here is link..
but in well known app it plays continues sound in driver side when app is in back ground and driver receives order.
and another issue is of when my app is in back ground and receives push notification Rather clicking on notification if i open app by pressing app icon it does not show me data of push. it is not possible to load data when press on app icon here is link
iOS Push notification issue
but same thing is done in well known app
With iOS 7+, use application:didReceiveRemoteNotification:fetchCompletionHandler:, which is called even if your app is in the background. iOS will even launch your app in the background if it's not already running, but if the user force quits the app, it will not be re-launched. If you enable the remote-notification background mode, you can run app code when the notification arrives. If you include the audio background mode, you could initiate a sound that continues to play while app is in background.
For second question, typically, your app should query a server for updates if it's launched directly. However, you could leverage a remote notification as above, which you'd get in most cases (except if the app were force quit).

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?

iPad app become inactive after locking screen

In my application, I'm downloading and uploading data at some point of time on a separate thread using NSOperation. Both process take approx. 2-3 min. If application remains active then everything works fine. But if the iPad screen is locked (automatically or manually), the app becomes inactive and download/upload get paused and when screen is unlocked after some time process failed with timeout error.
I have "App plays audio" for "Required background modes" in plist file. Do I need to set any other flag for running app while screen is locked?
Please help me what is going wrong.
When the screen is locked, your app becomes inactive. Per "Responding to Interruptions" in iOS App Programming Guide:
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.
You can get extra time for background tasks according to "Executing a Finite-Length Task in the Background" in the same guide:
Apps that are transitioning to the background can request an extra amount of time to finish any important last-minute tasks. To request background execution time, call the beginBackgroundTaskWithExpirationHandler: method of the UIApplication class. If your app moves to the background while the task is in progress, or if your app was already in the background, this method delays the suspension of your app. This can be important if your app is performing some important task, such as writing user data to disk or downloading an important file from a network server.
You can refer to the document to implement a finite-length download task in the background.
Other references:
Download data in background with iOS4
iOS Application Background Downloading

Resources