gpt4 book ai didi

ios - 蓝牙经典连接感知

转载 作者:行者123 更新时间:2023-11-29 10:32:54 29 4
gpt4 key购买 nike

我有一个蓝牙应用程序,可以通过低功耗与外围设备通信。

此外围设备还具有与 iOS 设备的经典(HFP 和/或 A2DP)连接。碰巧经典连接有时会中断。

我需要的是能够从应用程序中通知用户经典连接已丢失。

如何让我的应用程序识别经典连接?

你更喜欢用什么方式来做这件事?

最佳答案

虽然 CoreBluetooth 用于访问蓝牙 LE 或 4.0 设备,但您可以使用 ExternalAccessory 框架与其他蓝牙设备通信。

像这样:

- (void)registerForNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil];
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
}

- (void)accessoryDidConnect:(NSNotification *)notification
{
// Weird thing with ExternalAccessory where this notification is called more than once per accessory...
if ([[(EAAccessory *)[[(EAAccessoryManager *)notification.object connectedAccessories] lastObject] protocolStrings] count]) {
// Valid call
if ([[(EAAccessory *)[notification.userInfo valueForKey:EAAccessoryKey] protocolStrings] containsObject:/*Protocol string for the accessory*/]) {

}
}
}

- (void)accessoryDidDisconnect:(NSNotification *)notification
{
if ([[(EAAccessory *)[notification.userInfo valueForKey:EAAccessoryKey] protocolStrings] containsObject:/*Protocol string for the accessory*/]) {
// Disconnected
}
}

为此,您必须将“支持的外部附件协议(protocol)”键添加到应用的 info.plist 中,并在该键下的数组中列出蓝牙设备的协议(protocol)。

另请注意,要在 App Store 上分发,蓝牙设备必须在 Apple MFi 程序下注册,并且您必须是(设备制造商)认可的开发人员。

关于ios - 蓝牙经典连接感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696363/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com