4

IOS 5.0.1 iPhone 4S で Bluetooth を使用してデバイス検出を実装しようとしています。プライベート フレームワーク 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;

Bluetooth ヘッドセットが検出されました。deviceDiscovered コールバック関数が呼び出されますが、device.address には Bluetooth デバイスの MAC アドレスが含まれていません。アプリがクラッシュしています。また、device.name は、検出されたデバイスの名前ではなく、通知の名前 (BluetoothDeviceDiscoveredNotification) を返します。

この方法で Bluetooth ヘッドセットの MAC アドレスを取得するにはどうすればよいですか?

4

2 に答える 2

1

このコードを使用してください:

- (void)deviceDiscovered:(NSNotification *) notification {
    BluetoothDevice *bt = [notification object];
    NSLog(@"name: %@ address: %@",bt.name, bt.address);
于 2013-03-20T13:02:50.457 に答える
0

これが脱獄アプリの場合は、kLockdownBluetoothAddressKeyliblockdown.dylib 経由でキーを使用できます

于 2012-05-31T21:52:49.607 に答える