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/35495738/

相关文章:

ios - 从iOS应用程序向Bluetooth LE设备发送命令

ios - [__NSCFNumber countByEnumeratingWithState:objects:count:]:无法识别的选择器已发送到实例

iphone - EAOutputStream 写入 :maxLength: - 230 failed to write because stream does not have space available

android - PhoneGap、usb外接设备与Android主机模式的通信

来自 Web 应用程序的 iOS 外部附件框架

启动iOS模拟器时蓝牙耳机音乐质量变差

ios - iOS-断开蓝牙设备连接后自动调用的任何代表方法或通知

ios - 将 NSDates 从一个日历转换为另一个日历

ios - 在 iOS 8 的 UISplitViewController 中动画显示/隐藏主视图

javascript - 如何在 "ios contenteditable element"中格式化文本后恢复平滑滚动?