与CoreBluetooth配对后,是否可以通过ExternalAccessory框架访问蓝牙设备? [英] Can you access a bluetooth device via the ExternalAccessory framework after pairing with CoreBluetooth?

查看:297
本文介绍了与CoreBluetooth配对后,是否可以通过ExternalAccessory框架访问蓝牙设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFi程序中注册了一个蓝牙设备.我可以在iPhone设置中通过蓝牙配对设备,然后使用 Apple的EADemo 示例代码通过ExternalAccessory框架访问设备.

I have a Bluetooth device enrolled in the MFi program. I am able to pair the device via Bluetooth in the iPhone settings, and then use Apple's EADemo example code to access the device via the ExternalAccessory framework.

但是,我想知道是否有可能先通过CoreBluetooth在后台静默配对,然后使用ExternalAcessory框架与设备通信吗?

However, I'm wondering if it's possible to first silently pair in the background via CoreBluetooth, and then use the ExternalAcessory framework to communicate with the device?

我已经运行了一些实验,并且与CoreBluetooth配对后,ExternalAcessory框架没有显示已连接的设备.这可能是因为CoreBluetooth在Bluetooth Low Energy上运行,而ExternalAccessory可能在Bluetooth Classic上运行.

I've run some experiements and after pairing with CoreBluetooth, the ExternalAcessory framework shows no connected devices. This might be as CoreBluetooth opperates over Bluetooth Low Energy, and ExternalAccessory perhaps opperates over Bluetooth Classic.

尽管如此,从应用程序内配对设备,而不需要离开应用程序来访问设置,将会带来更好的用户体验.如果有人遇到这种情况或有任何想法,请随时分享任何建议.

Despite of this, it would be a much better user experience to pair the device from within an app, rather than needing to leave the app to access the settings. If anyone has been in this situation, or has any ideas, please feel free to share any suggestions.

推荐答案

如果使用ExternalAcessory,则无需依赖CoreBluetooth框架 double delayInSeconds = 2; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:nil]; });

No need to rely on the CoreBluetooth framework if you are working with ExternalAcessory double delayInSeconds = 2; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:nil]; });

单击该代码或在任何需要的位置,都将弹出一个窗口,其中显示了可用的MFI程序设备列表,您需要选择该设备并将其连接.

Put this code on a click of a button or wherever you want, this code will popup a window which will show the list of available MFI program devices, you need to select the device and it will get connected.

成功连接后,您会收到一条通知EAAccessoryDidConnectNotification,您需要收听此通知,并可以使用获取连接附件 - (void)_accessoryDidConnect:(NSNotification *)notification { EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey]; }

After successful connection , you will get a notification EAAccessoryDidConnectNotification, you need to listen this and you can get the connect accessory using - (void)_accessoryDidConnect:(NSNotification *)notification { EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey]; }

@ larromba-我希望您正在寻找这个.

@larromba- i hope you were looking for this.

这篇关于与CoreBluetooth配对后,是否可以通过ExternalAccessory框架访问蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆