Ios 蓝牙经典连接感知

Ios 蓝牙经典连接感知,ios,objective-c,bluetooth,bluetooth-lowenergy,core-bluetooth,Ios,Objective C,Bluetooth,Bluetooth Lowenergy,Core Bluetooth,我有一个蓝牙应用程序,通过低能耗与外围设备通信 此外围设备还具有与iOS设备的经典(HFP和/或A2DP)连接。有时,经典连接会被中断 我需要的是能够从应用程序中通知用户经典连接已丢失 如何让我的应用程序知道经典连接 您希望以何种方式执行此操作?当CoreBluetooth用于访问Bluetooth LE或4.0设备时,您可以使用外部附件框架与其他蓝牙设备通信 像这样: - (void)registerForNotifications { [[NSNotificationCenter d

我有一个蓝牙应用程序,通过低能耗与外围设备通信

此外围设备还具有与iOS设备的经典(HFP和/或A2DP)连接。有时,经典连接会被中断

我需要的是能够从应用程序中通知用户经典连接已丢失

如何让我的应用程序知道经典连接


您希望以何种方式执行此操作?

当CoreBluetooth用于访问Bluetooth LE或4.0设备时,您可以使用
外部附件
框架与其他蓝牙设备通信

像这样:

- (void)registerForNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil];
    [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
} 

- (void)accessoryDidConnect:(NSNotification *)notification
{
    // Weird thing with ExternalAccessory where this notification is called more than once per accessory...
    if ([[(EAAccessory *)[[(EAAccessoryManager *)notification.object connectedAccessories] lastObject] protocolStrings] count]) {
        // Valid call
        if ([[(EAAccessory *)[notification.userInfo valueForKey:EAAccessoryKey] protocolStrings] containsObject:/*Protocol string for the accessory*/]) {

        }
    }
}

- (void)accessoryDidDisconnect:(NSNotification *)notification
{
    if ([[(EAAccessory *)[notification.userInfo valueForKey:EAAccessoryKey] protocolStrings] containsObject:/*Protocol string for the accessory*/]) {
        // Disconnected
    }
}
为此,您必须将密钥“支持的外部附件协议”添加到应用程序的info.plist中,并在该密钥下列出阵列中蓝牙设备的协议


另外请注意,要在App Store上发布,蓝牙设备必须在Apple MFi程序下注册,并且您必须是(设备制造商)认可的开发人员。

对于非MFi设备,我发现获得有关连接的蓝牙经典设备的任何信息的唯一方法是(间接)通过AVAudioSession singleton。


从查看currentRoute属性开始。

通过经典连接,您的意思是您使用的是
外部附件
框架吗?如果是这样,您可以注册连接和断开连接的通知。不,我没有使用外部附件框架。我只使用CoreBluetooth,我的应用程序通过BLE与设备通信。但同一台设备也通过经典连接与iOS设备连接,因此它可以从iTunes传输音频。我可以让我的应用程序知道(经典)连接何时中断,以及如何中断?你所说的“经典连接”bluetooth 2.0是什么意思?如果没有足够的信息,很抱歉。我想通过“流媒体”可以理解HFP和/或A2DP。我会尝试外部附件框架。我将在下面的回答中发布代码。该设备来自其他供应商。我可以假定这不是我的问题吗?如果你试图发布一个使用非蓝牙LE的蓝牙连接的应用程序,苹果会让你失败,除非该设备在MFi程序中注册,并且你是公认的开发者。我有这个问题,现在切换到蓝牙LE设备,以节省自己的麻烦。