Obtaining a Bluetooth MAC Address Using a Private BluetoothManager

I am trying to implement device discovery using bluetooth in IOS 5.0.1 iPhone 4S. I am using the private framework BluetoothManager.

My code is:

- (IBAction)searchForDevices:(id)sender { [self.indicator setHidden:NO]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothAvailabilityChanged:) name:@"BluetoothAvailabilityChangedNotification" object:nil]; btCont = [BluetoothManager sharedInstance]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceDiscovered:) name:@"BluetoothDeviceDiscoveredNotification" object:nil]; } - (void)bluetoothAvailabilityChanged:(NSNotification *)notification { self.label.text = @"Availability changed!"; [btCont setDeviceScanningEnabled:YES]; } - (void)deviceDiscovered:(BluetoothDevice *)device { [self.indicator setHidden:YES]; self.label.text = device.address; 

My bluetooth headset is detected. The deviceDiscovered callback function is called, but device.address does NOT contain the MAC address of the Bluetooth device. The application is crashing. In addition, device.name returns the notification name (BluetoothDeviceDiscoveredNotification) instead of the name of the detected device.

Any suggestions how can I get the MAC address of my bluetooth headset this way?

Thanks!

+4
source share
2 answers

use this code:

 - (void)deviceDiscovered:(NSNotification *) notification { BluetoothDevice *bt = [notification object]; NSLog(@"name: %@ address: %@",bt.name, bt.address); 
+1
source

If this is a jailbreak application, you can use the kLockdownBluetoothAddressKey key via liblockdown.dylib

0
source

Source: https://habr.com/ru/post/1412712/


All Articles