IOS, how to detect a Bluetooth headset and its events

I am trying to open a “Bluetooth headset” and receive its events. I read the "CoreBluetooth" documentation and implemented a sample code as shown below. It does not run the delegate method " didDiscoverPeripheral".

Is there any solution for this?

the code:

CBCentralManager *myCentralManager;
[myCentralManager scanForPeripheralsWithServices:nil options:nil];


-(void)centralManagerDidUpdateState:(CBCentralManager *)central{

    //following line prints CBCentralManagerStatePoweredOn

    NSLog(@"state:%@", [self getCentralManagerState:central.state]);
}


//following method does not fire

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{

}
0
source share
2 answers

CoreBluetooth LE,
, , BluetoothHFP:
1. AVAudioSeesion:
link AVFoundation.framework
2. :

NSArray *availInputs = [[AVAudioSession sharedInstance] availableInputs];

3. :
. AVAudioSession
. AVAudioSessionRouteChangeNotification

- (BOOL)prepareAudioSession {

    // deactivate session
    BOOL success = [[AVAudioSession sharedInstance] setActive:NO error: nil];
    if (!success) {
        NSLog(@"deactivationError");
    }

    // set audio session category AVAudioSessionCategoryPlayAndRecord options AVAudioSessionCategoryOptionAllowBluetooth
    success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
    if (!success) {
        NSLog(@"setCategoryError");
    }

    // activate audio session
    success = [[AVAudioSession sharedInstance] setActive:YES error: nil];
    if (!success) {
        NSLog(@"activationError");
    }

    return success;
}

, :

[self prepareAudioSession];

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
                  selector:@selector(bluetoothAvailabilityDidChange:)
                      name:@"BluetoothConnectabilityChangedNotification"
                    object:nil];
  1. , Audio AirPlay :
    enter image description here

!! ,

+2

CoreBluetooth.framework Bluetooth Low-Energy.
Bluetooth Low-Energy ( , ..)
: , Bluetooth Low-Energy?
.

, centralManager:didDiscoverPeripheral: .

, , " ", . , " ", , MFI. , . , iOS- Bluetooth HeadSet, , .. ExternalAccessory.framework, , , .

+1

All Articles