Skip to content

Commit

Permalink
fix(iOS): should not init bluetooth on start
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Jan 8, 2025
1 parent ec7f49a commit 9b2fcb9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ios/TscBlue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ - (instancetype)init {
_nextId = 0;
_peripherals = [NSMutableDictionary new];
_characteristics = [NSMutableDictionary new];
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
return self;
}

- (void)initCentralManager {
if (_centralManager) return;
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}

RCT_EXPORT_METHOD(scanDevices:(double)timeout
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[self initCentralManager];
if (_centralManager.state != CBManagerStatePoweredOn) {
reject(@"E_BLUETOOTH_OFF", @"Bluetooth is not powered on", nil);
return;
Expand All @@ -57,6 +62,7 @@ - (instancetype)init {
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[self initCentralManager];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:target];
CBPeripheral *peripheral = [_centralManager retrievePeripheralsWithIdentifiers:@[uuid]].firstObject;

Expand Down

0 comments on commit 9b2fcb9

Please sign in to comment.