2012-03-19 13 views
5

私は、iOS 5.0のBluetoothManagerプライベートフレームワークを使用して近くのBluetoothデバイスを検出するための最小限の例を構築しています。この質問で見つかった答え使用最小iOS BluetoothManagerの例

Finding generic Bluetooth devices within reach

をここでBluetoothAvailabilityChangedNotificationに登録する私のviewDidLoadメソッドです。私は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]; 

私は、Bluetoothの可用性が通知を変更し得る場合には、前述のリンクで回答の1に概説されているように、私は、対応デバイスのスキャンを設定します。

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

完全性については、ここでdeviceDiscovered通知方法をご覧ください。次のようにテスト・アプリケーションを実行することによって生成

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

ログは、次のとおりです。

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

残念ながら、携帯電話は私が近接発見デバイスがある知っているにもかかわらず、すべての任意のBluetoothデバイスを拾っていません(Android搭載端末を使用して確認済み)。

いくつかのものは、私はすでに試してみました:

  • コーリング[btCont setPowered:YES];そして、関連する電力状態変更通知の登録、setDeviceScanningEnabled実行:YESコールバック
  • 呼び出しの[btCont resetDeviceScanning先行setDeviceScanningEnabledコールscanForConnectableDevicesを呼び出す
  • に:(unsigned int型)ARG1。 arg1がある種のタイムアウト値であるかもしれないと推測します。私は成功していない様々な価値を試しました。

どのような考えも大歓迎です。 ありがとう!

+0

すべての更新を?あなたは問題を解決することができましたか? scanForConnectableDevicesMethodについての情報はありますか? – Mahes

答えて

2

私が知る限り、ブルートゥースマネージャは、OSが結果をフィルタリングした後にリストを取得します。 近くのヘッドセットデバイスのみを取得し、すべての汎用デバイスを取得することはできません。

あなたはscanForServicesを使用する必要があります。

// start scan 
    [btManager setDeviceScanningEnabled:YES]; 
    [btManager scanForServices:0xFFFFFFFF];