可能产生于iOS连接的蓝牙设备的列表? [英] Possible to generate a list of connected bluetooth devices for iOS?

查看:245
本文介绍了可能产生于iOS连接的蓝牙设备的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确定哪些设备通过蓝牙连接iOS中,但似乎无法推测出来。理想情况下,我想产生连接的蓝牙设备列表。

I'm trying to determine what devices are connected via bluetooth in iOS but can't seem to figure it out. Ideally I'd like to generate a list of connected bluetooth devices.

我一直使用retrieveConnectedPeripheralsWithServices试图但这需要一个特定的服务来搜索。我想生成所有连接的蓝牙设备,而不仅仅是特定服务的蓝牙设备的列表。有没有办法,只是搜索所有服务,而无需通过一切可能的服务循环?

I've tried using "retrieveConnectedPeripheralsWithServices" but this requires a specific service to search for. I'd like to generate a list of all connected bluetooth devices, not just specific-service bluetooth devices. Is there a way to just search for all services without looping through all possible services?

任何想法?

推荐答案

下面是针对iOS(谢谢Larme)解决方案:

Here is solution for iOS (Thank you Larme) :

NSArray *connectedAccessories = [[EAAccessoryManager sharedAccessoryManager] connectedAccessories]; 

文件:

<一个href=\"https://developer.apple.com/library/$p$prelease/ios/documentation/ExternalAccessory/Reference/EAAccessoryManager_class/index.html#//apple_ref/occ/instp/EAAccessoryManager/connectedAccessories\" rel=\"nofollow\">https://developer.apple.com/library/$p$prelease/ios/documentation/ExternalAccessory/Reference/EAAccessoryManager_class/index.html#//apple_ref/occ/instp/EAAccessoryManager/connectedAccessories

另外,如果有人需要,这是文件的Mac:

Also if someone needs, this is documentation for Mac :

<一个href=\"https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/Bluetooth/BT_Intro/BT_Intro.html\" rel=\"nofollow\">https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/Bluetooth/BT_Intro/BT_Intro.html

和code段为Mac

and code snippet for Mac

NSArray *devices = [IOBluetoothDevice pairedDevices];

有关alan478的BLE问题:

For alan478's BLE question :

核心蓝牙框架提供需要为您的iOS和Mac应用程序与配备了蓝牙低功耗无线技术的设备进行通信的类。你可以看看这个教程:

The Core Bluetooth framework provides the classes needed for your iOS and Mac apps to communicate with devices that are equipped with Bluetooth low energy wireless technology. You can take a look this tutorial :

http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor

和BLE code段是:

and BLE code snippet is :

// In this case you need to tell UUID for serching specific device
CBUUID *hrate = [CBUUID UUIDWithString:@"1800"];

// Create a dictionary for passing down to the scan with service method
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

// Tell the central manager (cm) to scan for the heart rate service
[cm scanForPeripheralsWithServices:[NSArray arrayWithObject:hrate] options:scanOptions]

请阅读developer.apple.com这个文件:

<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/BestPracticesForInteractingWithARemotePeripheralDevice/BestPracticesForInteractingWithARemotePeripheralDevice.html\" rel=\"nofollow\">https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/BestPracticesForInteractingWithARemotePeripheralDevice/BestPracticesForInteractingWithARemotePeripheralDevice.html

这里是你的一个有趣的段落:

探索外设的数据明智
外围设备可能有更多的服务和性能比你可能有兴趣,当你正在开发一个应用程序来满足特定使用案例英寸发现所有的周边的服务和相关特性产生负面影响电池寿命和你的应用程序的性能。因此,你应该寻找和发现只有服务和相关的特性你的应用需求。

Explore a Peripheral’s Data Wisely A peripheral device may have many more services and characteristics than you may be interested in when you are developing an app to fulfill a specific use case. Discovering all of a peripheral’s services and associated characteristics can negatively affect battery life and your app’s performance. Therefore, you should look for and discover only the services and associated characteristics your app needs.

例如,假设您连接到具有可用许多服务的外围设备,但您的​​应用程序需要访问只是其中的两项。你可以寻找和发现仅这两项服务,通过他们的服务的UUID数组传递(通过重新对象CBUUID psented $ P $)的discoverServices:方法CBPeripheral类的,像这样的:

For example, imagine that you are connected to a peripheral device that has many services available, but your app needs access to only two of them. You can look for and discover these two services only, by passing in an array of their service UUIDs (represented by CBUUID objects) to the discoverServices: method of the CBPeripheral class, like this:

[peripheral discoverServices:@[firstServiceUUID, secondServiceUUID]];

您已经发现了两个服务你有兴趣,你同样可以寻找和发现这些服务,你有兴趣的唯一特征。再次后,只需通过在确定你想要的特性的UUID的数组发现(为每个服务)的discoverCharacteristics:forService:在CBPeripheral类的方法

After you have discovered the two services you are interested in, you can similarly look for and discover only the characteristics of these services that you are interested in. Again, simply pass in an array of the UUIDs that identify the characteristics you want to discover (for each service) to the discoverCharacteristics:forService: method of the CBPeripheral class.

也有这样的评论:

认为苹果禁止这个事情。我们只能用特定的CBUUID获得设备列表中。因此,如果要列出所有设备(与蓝牙设置确实本身),那么它是不可能的。请纠正我,如果我我错了 - Mrug 3月11日在13时24分

"think Apple forbids this thing. We can only get list of Devices with specific CBUUID. so if you want to list all the devices(same as the Bluetooth settings does natively) then It is not possible. Please correct me if i am wrong. – Mrug Mar 11 at 13:24"

根据这样的问题:

如何获得可用的蓝牙设备列表?

这篇关于可能产生于iOS连接的蓝牙设备的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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