Minimal iOS BluetoothManager Example

Estou construindo um exemplo mínimo para detectar dispositivos Bluetooth próximos usando a estrutura privada BluetoothManager no iOS 5.

Usando uma resposta encontrada nesta pergunta: Encontrar dispositivos Bluetooth genéricos ao alcance

Aqui está o meu método viewDidLoad para me registrar na BluetoothAvailabilityChangedNotification. Também me registro no BluetoothDeviceDiscoveredNotification.

[[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];

Quando recebo a notificação alterada de disponibilidade do Bluetooth, ativei a verificação do dispositivo, conforme descrito em uma das respostas no link mencionado acim

- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
    NSLog(@"BT State: %d", [btCont enabled]);
    [btCont setDeviceScanningEnabled:YES];
}

Para completar, aqui está o método de notificação deviceDiscovere

- (void)deviceDiscovered:(NSNotification *) notification
{
    NSLog(@"Discovered one!");
}

Os logs produzidos pela execução do aplicativo de teste são os seguintes:

BTM: attaching to BTServer
BTM: posting notification BluetoothAvailabilityChangedNotification
BT State: 1
BTM: setting device scanning enabled

nfelizmente, o telefone não está captando nenhum dispositivo Bluetooth, mesmo sabendo que existem dispositivos detectáveis próximos (verificados usando um dispositivo Android

Algumas coisas que eu já tentei:

Calling [btCont setPowered: YES]; e registrando-se para a notificação de alteração de estado de energia associada, executando setDeviceScanningEnabled: YES no retorno de chamadaCalling [btCont resetDeviceScanning] antes da chamada setDeviceScanningEnabled Chamando o scanForConnectableDevices: (unsigned int) arg1; , supondo que arg1 possa ser algum tipo de valor de tempo limite. Eu tentei uma variedade de valores sem sucesso.

Qualquer pensamento seria muito apreciado. Obrigado

questionAnswers(4)

yourAnswerToTheQuestion