从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];
    
    很简单:D

    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
        }
    }
    
    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
        }
    }