Can you access a bluetooth device via the ExternalAccessory framework after pairing with CoreBluetooth?

别说谁变了你拦得住时间么 提交于 2019-12-11 05:35:14

问题


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.

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?

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.


回答1:


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]; });

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.

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- i hope you were looking for this.



来源:https://stackoverflow.com/questions/39611629/can-you-access-a-bluetooth-device-via-the-externalaccessory-framework-after-pair

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!