Skip to content

Commit 3943feb

Browse files
committed
Merge pull request #24 from locly/master
Drop empty range calls
2 parents e341e1c + 4f32c18 commit 3943feb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ Beacons.stopUpdatingLocation();
147147

148148
This method should be called when you don't need to receive location-based information and want to save battery power.
149149

150+
### Beacons.shouldDropEmptyRanges
151+
```javascript
152+
Beacons.shouldDropEmptyRanges(true);
153+
```
154+
Call this method to stop sending the `beaconsDidRange` event when the beacon list is empty. This can be useful when listening to multiple beacon regions and can reduce cpu usage by 1-1.5%.
155+
150156
## Events
151157
To listen to events we need to call `DeviceEventEmitter.addListener` (`var {DeviceEventEmitter} = require('react-native')`) where the first parameter is the event we want to listen to and the second is a callback function that will be called once the event is triggered.
152158

RNBeacon.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@interface RNBeacon() <CLLocationManagerDelegate>
1818

1919
@property (strong, nonatomic) CLLocationManager *locationManager;
20+
@property (assign, nonatomic) BOOL dropEmptyRanges;
2021

2122
@end
2223

@@ -35,6 +36,7 @@ - (instancetype)init
3536

3637
self.locationManager.delegate = self;
3738
self.locationManager.pausesLocationUpdatesAutomatically = NO;
39+
self.dropEmptyRanges = NO;
3840
}
3941

4042
return self;
@@ -153,6 +155,11 @@ - (NSString *)stringForProximity:(CLProximity)proximity {
153155
[self.locationManager stopUpdatingLocation];
154156
}
155157

158+
RCT_EXPORT_METHOD(shouldDropEmptyRanges:(BOOL)drop)
159+
{
160+
self.dropEmptyRanges = drop;
161+
}
162+
156163
-(NSString *)nameForAuthorizationStatus:(CLAuthorizationStatus)authorizationStatus
157164
{
158165
switch (authorizationStatus) {
@@ -195,6 +202,9 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
195202
-(void) locationManager:(CLLocationManager *)manager didRangeBeacons:
196203
(NSArray *)beacons inRegion:(CLBeaconRegion *)region
197204
{
205+
if (self.dropEmptyRanges && beacons.count == 0) {
206+
return;
207+
}
198208
NSMutableArray *beaconArray = [[NSMutableArray alloc] init];
199209

200210
for (CLBeacon *beacon in beacons) {

0 commit comments

Comments
 (0)