2012-04-02 102 views
2

我正在开发博客演讲者应用程序。检测iOS5上禁用蓝牙功能

我想暂停音频时禁用蓝牙,如iPod应用程序。我认为在阅读本文后不使用私有API是不可能的。 Check if Bluetooth is Enabled?

但是,我的客户告诉我,Rhapsody和DI Radio应用程序都支持它。

然后我发现iOS5有Core蓝牙框架。 https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CoreBluetooth_Framework/CoreBluetooth_Framework.pdf

CBCentralManagerStatePoweredOff状态看起来像是一个。

但是,说明中说这个api只支持蓝牙4.0低功耗设备。 有没有人试过做同样的事情?

我想支持目前流行的蓝牙耳机,或蓝牙车载方向盘。我不知道是否值得尝试,当它只支持一些全新的蓝牙。

+1

我不确定实际问题在这里。检查CBCentralManagerState将允许您查看设备的蓝牙是打开还是关闭。 – mwright 2012-04-30 17:18:06

+0

谢谢,我会检查出来的! – 2012-05-01 04:35:47

回答

2

对于音频,专注于蓝牙特别的声音像错误的方法。我想你要找的是Handling Audio Hardware Route Changes

你会发现,所有的下列引起内置的iPod应用程序暂停:

  • 蓝牙设备被移除(可能是因为蓝牙已被禁用)。
  • 耳机未插电。
  • 设备从扩展坞移除。

当您使用音频会话API时,您会获得所有正确的行为。

+0

看来这是我想要的。如果我一次可以支持所有的行为,那就太好了。谢谢。 – 2012-07-16 04:34:10

1

在BLE你会得到包含状态管理器更新:

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. 
}; 

,你可以在强制回调检查与如

centralManager:didUpdateState...{ 
if ([manager state] == CBCentralManagerStatePoweredOff) 
{ 
[musicPlayer pause] 
} 
} 
+0

谢谢,我会检查出来的! – 2012-07-16 04:32:52