2016-04-27 11 views
0

私はBluetoothデバイスがiOSデバイスに接続されているかどうかを追跡しようとしています。didConnectPeripheralは決して呼ばれません

:私は/ iOS版からブルートゥースをdiactivate有効にすると、私がメッセージを受信

scDeviceManager *deviceManager = [scDeviceManager sharedInstance]; 

:私はオブジェクトscDeviceManagerを呼び出して、いくつかの点で

#import <Foundation/Foundation.h> 
#import <CoreBluetooth/CoreBluetooth.h> 


@interface scDeviceManager:NSObject <CBCentralManagerDelegate> 
@property (nonatomic, strong) CBCentralManager *centralManager; 

+ (scDeviceManager *) sharedInstance; 

@end 

#import "scDeviceManager.h" 


@implementation scDeviceManager 
@synthesize centralManager = _centralManager; 


+ (scDeviceManager *) sharedInstance { 

    static scDeviceManager *_sharedInstance=nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     _sharedInstance = [[self alloc] init]; 
    }); 

    return _sharedInstance; 
} 

- (id)init { 

    if (self = [super init]) { // equivalent to "self does not equal nil" 

     _centralManager=[[CBCentralManager alloc] initWithDelegate:self queue:nil]; 
     //also tried 
     //_centralManager=[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()]; 

    } 
    return self; 
} 


- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { 

    NSLog(@"Peripheral connected"); 
} 




- (void)centralManagerDidUpdateState:(CBCentralManager *)central{ 
    _log=[[Logger alloc] initWithClassName:NSStringFromClass([self class])]; 

    switch (central.state) { 
     case CBCentralManagerStatePoweredOff: 
      NSLog(@"CoreBluetooth BLE hardware is powered off."); 

      break; 
     case CBCentralManagerStatePoweredOn: 
      NSLog(@"CoreBluetooth BLE hardware is powered on and ready."); 
      [_centralManager scanForPeripheralsWithServices:nil options:nil]; 
      break; 
     case CBCentralManagerStateResetting: 
      NSLog(@"CoreBluetooth BLE hardware is resetting."); 
      break; 
     case CBCentralManagerStateUnauthorized: 
      NSLog(@"CoreBluetooth BLE state is unauthorized."); 
      break; 
     case CBCentralManagerStateUnknown: 
      NSLog(@"CoreBluetooth BLE state is unknown."); 
      break; 
     case CBCentralManagerStateUnsupported: 
      NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform."); 
      break; 
     default: 
      NSLog([NSString stringWithFormat:@"Nothing to do: state (%ld).",(long)central.state]); 
      break; 
    } 
} 

@end; 

:私は、次のコードを使用しています2016-04-27 13:33:21.940 CoreBluetooth BLEハードウェアの電源がオフです。

2016-04-27 13:33:24.046 CoreBluetooth BLEハードウェアの電源が入っており、 の準備ができています。

これは、Bluetoothが有効になっており、新しいBluetoothデバイスをスキャンしたことを示します。

ただし、Bluetoothデバイス(samsung HM1700、Bluetoothヘッドセット)を接続すると、didConnectPeripheralは呼び出されません。私は音楽を聴くことができるので、Bluetoothデバイスが接続されていることを確認してください。

MicrophoneBuiltIn:iPhoneマイク

BluetoothHFP:HM1700

私は

-(void) scanConnectedDevices{ 

    NSArray *inputs = [[AVAudioSession sharedInstance] availableInputs]; 
    for (AVAudioSessionPortDescription *port in inputs) 
    { 
     connectedAudioDevices[port.portType]=port; 
     NSLog(@"type:%@, name:%@",port.portyType,port.portName) 
    } 

} 

次の関数を呼び出し、私が取得することで、カスタムiOSのボタンで

これは、デバイスが接続されていることを示します。しかし、私は、Bluetoothデバイスを接続/切断するたびに代表者がコードの平和を実行することを望みます。

おかげ

+0

CoreBluetoothはBluetooth Low-Energy専用で、Samsung HM1700はBluetooth Low-Energyデバイスではありません。 – Larme

+0

Ic ...ブルートゥースヘッドセットの代理人がいることは可能ですか? –

+0

http://stackoverflow.com/questions/20896528/how-to-find-bluetooth-audio-devices-in-ios – Larme

答えて

0

私はそれが物事をミックスすることがいかに簡単であるか見ることができます;)何をやっている

: は、基本的には、メモリ内のブルートゥースインスタンスを作成します。 そして、あなたが設定を使用して、他のBluetoothデバイスを接続する 結果: 2つのものが、それぞれ、他に関連していない - 場合は>あなたの「コード」は、ヘッドセットについては何もあなたの接続形式別の場所を知らない...

別のBluetoothデバイスが接続されているかどうかを調べようとしています: おそらくMFIプログラムのメンバーになる必要があり、それであなた自身の製造元のヘッドセットに接続できるようになります。

そうでなければ、私が知っている限り、iOS上に接続された「古典的な」Bluetoothデバイスを「一覧表示」する方法はありません。

関連する問題