Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix android build, update beacon library #257

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
22 changes: 15 additions & 7 deletions ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*=-----------------------------------------------------------------------------------------------=
*/
@interface ESSBeaconScanner () <CBCentralManagerDelegate> {
CBCentralManager *_centralManager;
CBCentralManager *_internalCentralManager;
dispatch_queue_t _beaconOperationsQueue;

/**
Expand Down Expand Up @@ -61,18 +61,26 @@ - (instancetype)init {
_onLostTimeout = 5.0;
_tlmCache = [NSMutableDictionary dictionary];
_beaconOperationsQueue = dispatch_queue_create(kBeaconsOperationQueueName, NULL);
_centralManager = [[CBCentralManager alloc] initWithDelegate:self
queue:_beaconOperationsQueue];
}

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");
Expand All @@ -84,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];
}

Expand Down