【问题标题】:Detecting when Bluetooth is disabled on iOS5检测iOS5上何时禁用蓝牙
【发布时间】:2012-04-15 17:00:25
【问题描述】:

我正在开发博客扬声器应用程序。

我想在蓝牙被禁用时暂停音频,比如 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 低功耗设备。 有没有人尝试做同样的事情?

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

【问题讨论】:

  • 我不确定这里的实际问题是什么。检查 CBCentralManagerState 将允许您查看设备的蓝牙是打开还是关闭。

标签: iphone ios audio bluetooth audiosession


【解决方案1】:

对于音频,特别关注蓝牙听起来是错误的方法。

我想你要找的是Handling Audio Hardware Route Changes

您会注意到以下所有因素都会导致内置 iPod 应用程序暂停:

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

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

【讨论】:

  • 看来这就是我想要的。如果我能同时支持所有的行为,那就太好了。谢谢。
【解决方案2】:

在 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]
}
}

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2021-12-26
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    相关资源
    最近更新 更多