CoreBluetooth,BLE:无法发现外围设备

时间:2016-08-17 14:41:37

标签: ios objective-c core-bluetooth obd-ii dongle

我有一个我想连接的BLE设备(obd2加密狗)。我可以通过“设置”与它配对但我无法通过didDiscoverPeripheral委托方法发现它,任何帮助?

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    _centralManager =[[CBCentralManager alloc]initWithDelegate:self queue:nil]; 
    [self scan]; 
}

-(void)scan { 

    NSDictionary *options1 =@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }; 
    [_centralManager scanForPeripheralsWithServices:nil options:options1]; 
}

-(void)centralManagerDidUpdateState:(CBCentralManager *)central{ 
    if (central.state == CBCentralManagerStatePoweredOn) { 
        [self scan]; 
    } 
}

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI {

    [peripheral readRSSI];

    [central connectPeripheral:peripheral options:nil];

}

-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { 
    CBPeripheral *peripheral1 =peripheral; 
    NSLog(@"peripheral1 name = %@",peripheral1.name); peripheral.delegate=self; 
    [peripheral discoverServices:nil]; 
}

0 个答案:

没有答案
相关问题