swift: Silence warning if BLE power off on iOS
When advertising starts using the corebluetooth BLE plugin on iOS
(which happens at syncbase app boot), if the power is off then a
system UI warning will popup. This CL silences that warning.
Closes: vanadium/issues#1405
Change-Id: Icfb0375cf556535504f88e6a588a0863cc02a7f2
diff --git a/lib/discovery/plugins/ble/corebluetooth/CBAdvertisingDriver.m b/lib/discovery/plugins/ble/corebluetooth/CBAdvertisingDriver.m
index 6337922..3924393 100644
--- a/lib/discovery/plugins/ble/corebluetooth/CBAdvertisingDriver.m
+++ b/lib/discovery/plugins/ble/corebluetooth/CBAdvertisingDriver.m
@@ -29,7 +29,14 @@
- (id _Nullable)initWithQueue:(dispatch_queue_t _Nonnull)queue {
if (self = [super init]) {
self.queue = queue;
- self.peripheral = [[CBPeripheralManager alloc] initWithDelegate:self queue:self.queue];
+ self.peripheral =
+ [[CBPeripheralManager alloc] initWithDelegate:self
+ queue:self.queue
+ options:@{
+#if TARGET_OS_IPHONE
+ CBPeripheralManagerOptionShowPowerAlertKey : @NO
+#endif
+ }];
self.services = [NSMutableDictionary new];
self.serviceCharacteristics = [NSMutableDictionary new];
self.addServiceHandlers = [NSMutableDictionary new];
diff --git a/lib/discovery/plugins/ble/corebluetooth/CBScanningDriver.m b/lib/discovery/plugins/ble/corebluetooth/CBScanningDriver.m
index d00d0a7..e61306f 100644
--- a/lib/discovery/plugins/ble/corebluetooth/CBScanningDriver.m
+++ b/lib/discovery/plugins/ble/corebluetooth/CBScanningDriver.m
@@ -112,7 +112,14 @@
- (id _Nullable)initWithQueue:(dispatch_queue_t _Nonnull)queue {
if (self = [super init]) {
self.queue = queue;
- self.central = [[CBCentralManager alloc] initWithDelegate:self queue:self.queue];
+ self.central =
+ [[CBCentralManager alloc] initWithDelegate:self
+ queue:self.queue
+ options:@{
+#if TARGET_OS_IPHONE
+ CBCentralManagerOptionShowPowerAlertKey : @NO
+#endif
+ }];
[self _initDiscovery];
}
return self;