我需要制作一个应用程序,能够判断我当前是否连接到经典蓝牙设备(实际上,它将是蓝牙汽车设备)。
我的第一步是了解当前连接的经典蓝牙设备是什么。我无法使用 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/