No and Yes, bluetooth-central background mode is just for you to handle Bluetooth callbacks. It won’t give you time to execute other code.
For that you need to ask the OS for time to execute. Like this.
__block UIBackgroundTaskIdentifier task = nil;
// Ask application for time to execute code in the background
task = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
// This will be called if you don’t call endBackgroundTask in some time
// (~10 min is the popular opinion)
// Clean up your state here.
// If you don’t call endBackgroundTask here you app will be terminated
[[UIApplication sharedApplication] endBackgroundTask:task];
}];
// execute your code to record audio
// Release the background task.
[[UIApplication sharedApplication] endBackgroundTask:task];
There is no guarantee that your code will get enough time to execute in the background. Write your code to handle that gracefully.
Note that this code should always be called when you want to record your audio since you never know when the app will enter background mode.
Regards,
Joakim
From: bluetooth-dev-bounces+jfernstad=email@hidden [mailto:bluetooth-dev-bounces+jfernstad=email@hidden]
On Behalf Of Javaid, Bilal
Sent: Friday, August 23, 2013 9:53 AM
To: email@hidden
Subject: Bluetooth Background Mode
I understand that I can use bluetooth-central background mode to maintain a connection and handle bluetooth events in the background.
This has been working, but I would like to turn on the microphone and start listening for 1 minute when the App receives a particular bluetooth event, in the background.
I have tried this with the OpenEars Framework, and it works in the foreground, but it stops listening when the App enters the background. And if I try to start
listening while in the background, I get an error from AudioSession.
So I am wondering if this should even be possible? Or do bluetooth-central permissions not allow this to happen?