Question

I'm developing blog speaker app.

I wanna pause the audio when bluetooth is disabled like iPod app. I thought it's not possible without using private api after reading this. Check if Bluetooth is Enabled?

But, my customer told me that Rhapsody and DI Radio apps both support it.

Then I found iOS5 has Core Bluetooth framework. https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CoreBluetooth_Framework/CoreBluetooth_Framework.pdf

CBCentralManagerStatePoweredOff status seems like the one.

But, the description says this api only supports Bluetooth 4.0 low energy devices. Did anyone try doing the same thing?

I want to support current popular bluetooth headsets, or bluetooth enabled steering wheel on the car. I don't know if it's worth trying when it only supports some brand new bluetooth.

Was it helpful?

Solution

For audio, focusing on Bluetooth specifically sounds like the wrong approach.

I think what you're looking for is Handling Audio Hardware Route Changes.

You'll notice that all of the following cause the the built-in iPod app to pause:

  • Bluetooth device is removed (possibly because bluetooth has been disabled).
  • Headphones are unplugged.
  • Device is removed from docking station.

You get all that correct behavior when you use the Audio Session API.

OTHER TIPS

On BLE you will get an update on the manager containing the state:

 enum {
CBCentralManagerStateUnknown = 0, // State unknown,
update imminent.
CBCentralManagerStateResetting, // The connection with the system service was      momentarily lost,
update imminent.
CBCentralManagerStateUnsupported, // The platform doesn't support Bluetooth Low Energy.
CBCentralManagerStateUnauthorized, // The app is not authorized to use Bluetooth Low Energy.
CBCentralManagerStatePoweredOff, // Bluetooth is currently powered off.
CBCentralManagerStatePoweredOn, // Bluetooth is currently powered on and available to use.
};

which you can check on the mandatory callback with e.g

centralManager:didUpdateState...{
if ([manager state] == CBCentralManagerStatePoweredOff)
{
[musicPlayer pause]
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top