如何检测iphone是否连接到任何蓝牙设备? [英] How to detect if a iphone is connected to any bluetooth device or not?

查看:1480
本文介绍了如何检测iphone是否连接到任何蓝牙设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 7中遇到了这个新API。

I came across this new API from iOS 7.

- (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs NS_AVAILABLE(NA, 7_0);

所以很明显,如果返回数组的数量大于0,则连接到至少一个设备。
但是在使用这个API之前,我无法弄清楚我必须在这里传递的参数(serviceUUIDs)。
有人可以在这里用一个例子来解释吗?

So its pretty clear that if the return array count is greater than 0 than its connected to atleast one device. But before using this API I am not able to figure it out the argument (serviceUUIDs) that I have to passed here. Can someone explain here with an example?

推荐答案

除非你至少知道一个,否则你不能使用这个方法设备暴露的服务。您可以尝试使用常见服务,例如设备信息 - 0x180A - 因为大多数BLE设备都会宣传此服务,但不能保证。

You can't use this method unless you know at least one service exposed by the device. You could try using a common service, such as Device Information - 0x180A - as most BLE devices will advertise this service but it is not guaranteed.

CBUUID *deviceInfoUUID = [CBUUID UUIDWithString: @"180A"];
[cbCentral retrieveConnectedPeripheralsWithServices:@[deviceInfoUUID]];

传统音频设备(耳机,A2DP设备等)通过音频会话类作为音频设备可见 -

Legacy audio devices (headsets, A2DP devices etc) are visible as audio devices through the audio session classes -

检测连接的音频设备iOS

这篇关于如何检测iphone是否连接到任何蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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