Skip to content

Commit

Permalink
Prevent API warnings on iOS if Bluetooth is disabled during timed scan
Browse files Browse the repository at this point in the history
  • Loading branch information
peitschie committed May 20, 2023
1 parent b728ffc commit 4601ef1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/ios/BLECentralPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,7 @@ - (void)startScanWithOptions:(CDVInvokedUrlCommand*)command {

- (void)stopScan:(CDVInvokedUrlCommand*)command {
NSLog(@"stopScan");
[scanTimer invalidate];
scanTimer = nil;

if ([manager state] == CBManagerStatePoweredOn) {
[manager stopScan];
}
[self internalStopScan]

if (discoverPeripheralCallbackId) {
discoverPeripheralCallbackId = nil;
Expand Down Expand Up @@ -608,13 +603,7 @@ - (void)writeL2Cap:(CDVInvokedUrlCommand *)command {

-(void)stopScanTimer:(NSTimer *)timer {
NSLog(@"stopScanTimer");
[scanTimer invalidate];
scanTimer = nil;
[manager stopScan];

if (discoverPeripheralCallbackId) {
discoverPeripheralCallbackId = nil;
}
[self internalStopScan]
}

#pragma mark - CBCentralManagerDelegate
Expand Down Expand Up @@ -1221,4 +1210,17 @@ - (id) tryDecodeBinaryData:(id)value {
return value;
}

- (void) internalStopScan {
[scanTimer invalidate];
scanTimer = nil;

if ([manager state] == CBManagerStatePoweredOn) {
[manager stopScan];
}

if (discoverPeripheralCallbackId) {
discoverPeripheralCallbackId = nil;
}
}

@end

0 comments on commit 4601ef1

Please sign in to comment.