From d316364abd4e194db814423ce3ab40df654fb0a1 Mon Sep 17 00:00:00 2001 From: "david.martinez" Date: Thu, 15 Dec 2022 15:01:09 +0100 Subject: [PATCH 1/3] fix android build, update beacon library --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index d2567825..55359823 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -105,5 +105,5 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.facebook.react:react-native:0.6+' implementation 'com.intellij:annotations:+@jar' - compile 'org.altbeacon:android-beacon-library:2.16.1' + implementation 'org.altbeacon:android-beacon-library:2.19.4' } From aa7b56eb5126343965ff82ea1675dcbc9780f765 Mon Sep 17 00:00:00 2001 From: "david.martinez" Date: Fri, 23 Dec 2022 08:17:43 +0100 Subject: [PATCH 2/3] do not show power alert --- ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m b/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m index 57eee79b..9346af60 100644 --- a/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m +++ b/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m @@ -62,7 +62,8 @@ - (instancetype)init { _tlmCache = [NSMutableDictionary dictionary]; _beaconOperationsQueue = dispatch_queue_create(kBeaconsOperationQueueName, NULL); _centralManager = [[CBCentralManager alloc] initWithDelegate:self - queue:_beaconOperationsQueue]; + queue:_beaconOperationsQueue + options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}]; } return self; From 6c1b36d5e1c47784f1322b74195793d33495f4dc Mon Sep 17 00:00:00 2001 From: "david.martinez" Date: Fri, 23 Dec 2022 08:25:56 +0100 Subject: [PATCH 3/3] do not ask for permissions at app start --- ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m b/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m index 9346af60..6c274dfc 100644 --- a/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m +++ b/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m @@ -29,7 +29,7 @@ *=-----------------------------------------------------------------------------------------------= */ @interface ESSBeaconScanner () { - CBCentralManager *_centralManager; + CBCentralManager *_internalCentralManager; dispatch_queue_t _beaconOperationsQueue; /** @@ -61,19 +61,26 @@ - (instancetype)init { _onLostTimeout = 5.0; _tlmCache = [NSMutableDictionary dictionary]; _beaconOperationsQueue = dispatch_queue_create(kBeaconsOperationQueueName, NULL); - _centralManager = [[CBCentralManager alloc] initWithDelegate:self - queue:_beaconOperationsQueue - options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}]; } return self; } +-(CBCentralManager *)centralManager { + // Calling init() for the first time will ask the user to give the app the permission + // To prevent this happening on app start, we will delay this for the first call + if (_internalCentralManager == nil) { + _internalCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:_beaconOperationsQueue options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}]; + [NSThread sleepForTimeInterval: 0.05]; // Calling directly after init() will give us .Unknown. So just sleep for 50ms to prevent this + } + return _internalCentralManager; +} + - (void)startScanning { dispatch_async(_beaconOperationsQueue, ^{ - if (_centralManager.state != CBCentralManagerStatePoweredOn) { + if ([self centralManager].state != CBCentralManagerStatePoweredOn) { NSLog(@"CBCentralManager state is %ld, cannot start or stop scanning", - (long)_centralManager.state); + (long)[self centralManager].state); _shouldBeScanning = YES; } else { NSLog(@"Starting to scan for Eddystones"); @@ -85,14 +92,14 @@ - (void)startScanning { // We do not want multiple discoveries of the same beacon to be coalesced into one. // (Unfortunately this is ignored when we are in the background.) NSDictionary *options = @{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }; - [_centralManager scanForPeripheralsWithServices:services options:options]; + [[self centralManager] scanForPeripheralsWithServices:services options:options]; } }); } - (void)stopScanning { _shouldBeScanning = NO; - [_centralManager stopScan]; + [[self centralManager] stopScan]; [self clearRemainingTimers]; }