我正在尝试在 IOS 5.0.1 iPhone 4S 中使用蓝牙实现设备发现。
我正在使用私有框架BluetoothManager。
我的代码是:
- (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),而不是发现的设备的名称。
有什么建议我如何通过这种方式检索我的蓝牙耳机的 MAC 地址吗?
使用此代码:
- (void)deviceDiscovered:(NSNotification *) notification {
BluetoothDevice *bt = [notification object];
NSLog(@"name: %@ address: %@",bt.name, bt.address);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)