0

我有一个要连接的 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]; 
}
4

0 回答 0