Skip to content

Commit

Permalink
iOS BLE: also list paired and connected devices on BLE scan
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed Jan 17, 2024
1 parent d9f4005 commit 6400cf3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions App/ios/RCTRFIDWithUHFBLEModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ @implementation RCTRFIDWithUHFBLEModule
@try {
[[RFIDBlutoothManager shareManager] setFatScaleBluetoothDelegate:self];

// Try to connect a paired device
// Try to connect device directly
BOOL result = [[RFIDBlutoothManager shareManager] connectPeripheralWithIdentifier:identifier];
if (result == YES) {
resolve(@(true));
return;
}

// Or try to search and connect to a unpaired device
// Or try to search and connect to a device
self->searchForConnectToIdentifier = identifier;
[[RFIDBlutoothManager shareManager] startBleScan];
[[RFIDBlutoothManager shareManager] initSoundIfNeeded];
Expand Down
18 changes: 18 additions & 0 deletions App/ios/RFIDBlutoothManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,25 @@ - (void)startBleScan
[[NSRunLoop mainRunLoop] addTimer:_connectTime forMode:NSRunLoopCommonModes];
// }
self.uuidDataList=[[NSMutableArray alloc]init];

// Create a CBUUID object with the desired UUID string
NSArray *serviceUUIDs = @[[CBUUID UUIDWithString:@"6E400001-B5A3-F393-E0A9-E50E24DCCA9E"]];

[self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @ YES}];

// Retrieve connected peripherals
NSArray *connectedPeripherals = [self.centralManager retrieveConnectedPeripheralsWithServices:serviceUUIDs];

// Iterate over the connected peripherals and report
for (CBPeripheral *peripheral in connectedPeripherals) {
BLEModel *model=[BLEModel new];
model.nameStr=peripheral.name;
model.rssStr=[NSString stringWithFormat:@"%d", 0];
model.addressStr=[peripheral.identifier UUIDString];
model.peripheral=peripheral;
[self.managerDelegate receiveDataWithBLEmodel:model result:@"0"];
}

}
- (void)connectTimeroutEvent
{
Expand Down

0 comments on commit 6400cf3

Please sign in to comment.