I am wondering if there is a way i can get an IOBluetoothDevice *
object from a CBPeripheral *
object because I am making an advanced bluetooth controller framework (Its going to be based on IOBluetooth
) and Im using it so scan for Bluetooth Classic
and Bluetooth Low Energy
devices. Here are some of the problems:
IOBluetooth
does allow you to search for both networks but for some reason its not showing up all of the Bluetooth Low Energy
Devices that CoreBluetooth
is.
If I use CoreBluetooth
to search for Bluetooth Low Energy
Devices I won't be able to get the address which I require for later use.
So is there any way i can get an IOBluetoothDevice
object from a CBPeripheral
?
thanks :D
I found out that I can search through /Library/Preferences/com.apple.bluetooth.plist > CoreBluetoothCache
which just happens to contain the UUID and in its dictionary DeviceAddress
= the address ;).
so I can get the UUID of a CBPeripheral
by using the method
NSString *uuid = [[<*CBPeripheral*> identifier] UUIDString];
and then looking it up in the property list
NSDicionary *btdict = [NSDictionary dictionaryWithContentsOfFile:@"/Library/Preferences/com.apple.bluetooth.plist"];
NSDictionary *bleDevices = [btDict objectForKey:@"CoreBluetoothCache"];
NSString *address = [[bleDevices objectForKey:uuid] objectForKey:@"DeviceAddress"];
Then create a new IOBluetoothDevice with that address:
IOBluetoothDevice *device = [IOBluetoothDevice deviceWithAddressString:address];
Its as easy as that :D