私は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デバイスを接続/切断するたびに代表者がコードの平和を実行することを望みます。
おかげ
CoreBluetoothはBluetooth Low-Energy専用で、Samsung HM1700はBluetooth Low-Energyデバイスではありません。 – Larme
Ic ...ブルートゥースヘッドセットの代理人がいることは可能ですか? –
http://stackoverflow.com/questions/20896528/how-to-find-bluetooth-audio-devices-in-ios – Larme