ios - 获取经典蓝牙连接设备列表(无BLE)[EAAccessoryManager]

标签 ios external-accessory ios-bluetooth

我需要制作一个应用程序,能够判断我当前是否连接到经典蓝牙设备(实际上,它将是蓝牙汽车设备)。

我的第一步是了解当前连接的经典蓝牙设备是什么。我无法使用 CoreBluetooth,因为它仅适用于 LE。我尝试使用外部附件框架。

这是代码(一个按钮启动该方法):

- (IBAction)startMethodGetConnected:(id)sender {
     NSLog(@"button taped");
     // Get the number of accessories connected
     NSUInteger NumberOfAccessoriesConnected = [[EAAccessoryManager sharedAccessoryManager].connectedAccessories count];
     //Display the number 
     NSLog(@"number of accessories connected : %d", NumberOfAccessoriesConnected);
 }

我尝试过将 iPhone 连接到蓝牙键盘和蓝牙耳机。在这两种情况下,控制台都会显示数字为 0。

如何显示正确的数字?

最佳答案

来自苹果文档:

"Applications that support external accessories must be sure to configure their Info.plist file correctly. Specifically, you must include the UISupportedExternalAccessoryProtocols key to declare the specific hardware protocols your application supports. For more information about this framework, see External Accessory Programming Topics." here

您需要使用 MFi 设备的协议(protocol)将此 key 添加到您的 Info.plist 文件中。

<key>UISupportedExternalAccessoryProtocols</key>
<array>
    <string>your_protocol_name</string>
</array>

问候

关于ios - 获取经典蓝牙连接设备列表(无BLE)[EAAccessoryManager],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56592311/

相关文章:

bluetooth-lowenergy - 当应用程序被系统杀死时不会调用 WillRestoreState

ios - 停止在 SceneKit 中的 Node 上播放声音

ios - 如何从数组中获取值并将其存储为坐标

ios - 如何使用文档提供程序扩展?

ios - 如何在 iOS 中查找蓝牙音频设备

iOS BLE 连接后立即断开连接,只有重启设备有帮助

iphone - 再次设置滚动框大小时滚动禁用

iphone - External Accessory 读取问题

iOS/swift : Automatically Pair With Bluetooth Classic Device

ios - 如何在 iOS 上删除配对的蓝牙设备?