使用BluetoothManager私人框架蓝牙获取MAC地址 [英] Getting MAC address of a bluetooth using BluetoothManager private framework

查看:908
本文介绍了使用BluetoothManager私人框架蓝牙获取MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现使用IOS 5.0.1 iPhone 4S的蓝牙设备发现。
我使用的是私有的框架BluetoothManager。

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

我的code是:

- (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;

我的蓝牙耳机被发现。
deviceDiscovered回调函数被调用,
但device.address不包含蓝牙设备的MAC地址。该应用程序崩溃。
另外,device.name返回而不是发现的设备的名称的通知(BluetoothDeviceDiscoveredNotification)的名称

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.

任何建议,我怎么能找回我的蓝牙耳机的MAC地址这种方式?

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

谢谢!

推荐答案

使用code:

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

这篇关于使用BluetoothManager私人框架蓝牙获取MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆