具有 iOS ExternalAccessoryFramework 的蓝牙经典

Bluetooth Classic with iOS ExternalAccessoryFramework

我正在考虑开发一个 iOS 应用程序,它将使用 iOS Supported Bluetooth Profiles

与蓝牙经典设备通信

据我了解,使用外部附件框架应该可以做到这一点,并且不需要参与 MFi 计划。来自 MFi FAQ:

What types of accessories and technologies are not part of the MFi Program?

Accessories that do not use any of the MFi licensed technology listed above are not part of the MFi Program. For example:

到目前为止,还不错。 External Accessory Framework doc 介绍说(强调):

The External Accessory framework provides support for communicating with external hardware connected to an iOS-based device through the 30-pin dock connector or wirelessly using Bluetooth. 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.

上面提到的 "specific hardware protocols" 的值在哪里记录?我假设这是指蓝牙配置文件?

FWIW,我已经下载并尝试 运行 Apple's EADemo app。它包括 UISupportedExternalAccessoryProtocols 键的值 com.apple.p1 和 com.apple.p2。当我 运行 第 4 代 iPod Touch/iOS8.1.3 上的 EADemo 应用程序时,它没有找到任何 BT 设备。它应该找到它所连接的 Jawbone 扬声器。

为了简化,我还创建了一个非常小的示例应用程序来侦听 EAAccessoryDidConnectNotification 通知:

- (void)viewDidLoad {
    [super viewDidLoad];        
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil];
    [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];

}

- (void) accessoryDidConnect:(NSNotification *)notification {
    EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey];
    NSLog(@"didConnect: %@", connectedAccessory.name);
}

当我 运行 iPod Touch 上的代码时,没有收到任何通知。虽然该应用正在 运行ning。我已关闭 Jawbone 扬声器,然后再打开以启动连接。 (我可以通过查看“设置”->“蓝牙”来确认它确实连接了)。

我已将 UISupportedExternalAccessoryProtocols 键添加到应用程序 plist 并将值数组留空并添加 com.apple.p1 和 com.apple.p2(如在 EADemo 应用程序中)。

关于我遗漏的任何想法?如何使 iOS 应用程序与蓝牙经典设备进行通信?

TL;DR:EA 框架仅适用于 MFi 设备。

来自 Apple 技术开发人员支持:

Hello Tom,

In response to your questions regarding the use of the External Accessory framework

Q1. If I'm attempting to programmatically connect to a BT device with any of these profiles using the EA framework, must the device be MFi compliant? Response - yes. The Accessory must implement a special protocol to identify data to be sent/received across the selected transport as EA supported data.

Q2. As an example, can I write code using the EA framework to connect to a Bluetooth speaker that is not MFi compliant? Response - Most Classic Bluetooth speakers use AVRCP/A2DP to transport audio data across Bluetooth with an iPhone. Such data is completely separate from the data marked for External Accessory support. The EA framework cannot be used to access the data sent via AVRCP/A2DP. However some speakers do implement a separate EA data exchange, which will work with an EA Framework application. However the direct answer - no. An EA framework app will opnly function with an MFI compliant accessory - even more of a subset - one desigend for use with EA.

Comment - Jawbone speaker does not appear in UITableView in the EADemo application. Response - this is correct. The Jawbone speaker is not an EA accessory. However the Nike Fuelband is an EA Accessory. An important consideration - to use the EA Framework, you must work with the accessory vendor to learn the data protocol supported by the accessory - what the data looks like when receiving and sending data.