Getting MAC address of a bluetooth using BluetoothManager private framework

馋奶兔 提交于 2019-12-14 03:47:41

问题


I'm trying to implement device discovery using bluetooth in IOS 5.0.1 iPhone 4S. I'm 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 discovered. deviceDiscovered callback function is called, but device.address does NOT contain the MAC address of the bluetooth device. The app is crashing. Also, device.name return the name of the notification (BluetoothDeviceDiscoveredNotification) instead of the name of the device discovered.

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

Thanks!


回答1:


use this code:

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



回答2:


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



来源:https://stackoverflow.com/questions/10613036/getting-mac-address-of-a-bluetooth-using-bluetoothmanager-private-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!