从CBPeripal*获取IOBluetoothDevice*(Mac OS X)
我想知道是否有一种方法可以从从CBPeripal*获取IOBluetoothDevice*(Mac OS X),bluetooth,core-bluetooth,iobluetooth,Bluetooth,Core Bluetooth,Iobluetooth,我想知道是否有一种方法可以从cbperipal*对象获取IOBluetoothDevice*对象,因为我正在制作一个高级蓝牙控制器框架(它将基于IOBluetooth)我正在使用它,以便扫描蓝牙经典和蓝牙低能设备。以下是一些问题: IOBluetooth确实允许您搜索两个网络,但由于某些原因,它不会显示corebooth使用的所有Bluetooth低能设备 如果我使用corebooth搜索Bluetooth低能设备,我将无法获得我以后使用所需的地址 那么有没有办法从cbperipal获取IOBl
cbperipal*
对象获取IOBluetoothDevice*
对象,因为我正在制作一个高级蓝牙控制器框架(它将基于IOBluetooth
)我正在使用它,以便扫描蓝牙经典
和蓝牙低能
设备。以下是一些问题:
IOBluetooth
确实允许您搜索两个网络,但由于某些原因,它不会显示corebooth
使用的所有Bluetooth低能设备
corebooth
搜索Bluetooth低能设备,我将无法获得我以后使用所需的地址
cbperipal
获取IOBluetoothDevice
对象呢
谢谢:D我发现我可以搜索
/Library/Preferences/com.apple.bluetooth.plist>coreblueouthcache
,它恰好包含UUID及其字典设备地址
=地址;)
因此,我可以使用该方法获得CBPeripheral
的UUID
NSString *uuid = [[<*CBPeripheral*> identifier] UUIDString];
然后使用该地址创建一个新的IOBluetooth设备:
IOBluetoothDevice *device = [IOBluetoothDevice deviceWithAddressString:address];
就这么简单:D我发现我可以搜索
/Library/Preferences/com.apple.bluetooth.plist>coreblueouthcache
,它恰好包含UUID和它的字典DeviceAddress
=地址;)
因此,我可以使用该方法获得CBPeripheral
的UUID
NSString *uuid = [[<*CBPeripheral*> identifier] UUIDString];
然后使用该地址创建一个新的IOBluetooth设备:
IOBluetoothDevice *device = [IOBluetoothDevice deviceWithAddressString:address];
很简单:DSwift 5.3解决方案:
fileprivate func getDeviceAddress(for cbPeripheral: CBPeripheral) -> String?
{
if let userDefaults = UserDefaults(suiteName: "/Library/Preferences/com.apple.Bluetooth")
{
if let coreBluetoothCache = userDefaults.object(forKey: "CoreBluetoothCache") as? [String : Any]
{
if let deviceData = coreBluetoothCache[cbPeripheral.identifier.uuidString] as? [String : Any]
{
return deviceData["DeviceAddress"] as? String
}
}
}
return nil
}
用法:
if let deviceAddress = self.getDeviceAddress(for: peripheral)
{
if let bluetoothDevice = IOBluetoothDevice(addressString: deviceAddress)
{
// Do your stuff
}
}
Swift 5.3解决方案:
fileprivate func getDeviceAddress(for cbPeripheral: CBPeripheral) -> String?
{
if let userDefaults = UserDefaults(suiteName: "/Library/Preferences/com.apple.Bluetooth")
{
if let coreBluetoothCache = userDefaults.object(forKey: "CoreBluetoothCache") as? [String : Any]
{
if let deviceData = coreBluetoothCache[cbPeripheral.identifier.uuidString] as? [String : Any]
{
return deviceData["DeviceAddress"] as? String
}
}
}
return nil
}
用法:
if let deviceAddress = self.getDeviceAddress(for: peripheral)
{
if let bluetoothDevice = IOBluetoothDevice(addressString: deviceAddress)
{
// Do your stuff
}
}