这是iOS的解决方案(谢谢Larme):
NSArray *connectedAccessories = [[EAAccessoryManager sharedAccessoryManager] connectedAccessories];
Run Code Online (Sandbox Code Playgroud)
说明文件:
另外,如果有人需要,这是Mac的文档:
和Mac的代码段
NSArray *devices = [IOBluetoothDevice pairedDevices];
Run Code Online (Sandbox Code Playgroud)
对于alan478的BLE问题:
核心蓝牙框架提供了您的iOS和Mac应用程序与配备了蓝牙低能耗无线技术的设备进行通信所需的类。您可以看一下本教程:
http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor
和BLE代码段是:
// 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]
Run Code Online (Sandbox Code Playgroud)
请在developer.apple.com上阅读此文档:
这是一段有趣的段落:
明智地探索外围设备的数据外围设备在开发应用程序以满足特定用例时可能比您感兴趣的服务和特性更多。发现外围设备的所有服务和相关特征可能会对电池寿命和应用程序性能产生负面影响。因此,您应该寻找并仅发现应用所需的服务和相关特征。
例如,假设您已连接到具有许多可用服务的外围设备,但是您的应用仅需要访问其中的两项。您可以通过将它们的服务UUID(由CBUUID对象表示)的数组传递到CBPeripheral类的discoverServices:方法中来查找和发现这两个服务,如下所示:
[peripheral discoverServices:@[firstServiceUUID, secondServiceUUID]];
Run Code Online (Sandbox Code Playgroud)
发现了您感兴趣的两个服务之后,您可以类似地查找并仅发现您感兴趣的这些服务的特征。同样,只需传入标识您要发现的特征的UUID数组即可( (针对每个服务)到CBPeripheral类的discoverCharacteristics:forService:方法。
也有此评论:
“认为Apple禁止使用此设备。我们只能获取具有特定CBUUID的设备列表。因此,如果您要列出所有设备(与Bluetooth设置相同),则不可能。如果我错了,请更正我。 – Mrug 3月11日13:24“
在这个问题下:
归档时间: |
|
查看次数: |
11112 次 |
最近记录: |