Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ReactNativeBeaconsManager.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Pod::Spec.new do |s|
s.name = "ReactNativeBeaconsManager"
s.version = "1.0.8"
s.summary = "React-Native library for detecting beacons (iOS and Android)"
s.homepage = "https://github.com/MacKentoch/react-native-beacons-manager#readme"
s.license = { :type => "MIT" }
s.authors = { "" => "" }
s.platform = :ios, "8.0"
s.source = { :path => "." }
s.source_files = "ios", "ios/**/*.{h,m}"
end
1 change: 1 addition & 0 deletions examples/BeaconsDemo/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class BeaconsDemo extends Component {
// you also have to add "Privacy - Location Always Usage Description" in your "Info.plist" file
// otherwise monitoring won't work
Beacons.requestAlwaysAuthorization();
Beacons.shouldDropEmptyRanges(true);
// Define a region which can be identifier + uuid,
// identifier + uuid + major or identifier + uuid + major + minor
// (minor and major properties are numbers)
Expand Down
12 changes: 9 additions & 3 deletions examples/samples/ranging.ios.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { NativeEventEmitter } from 'react-native'
import Beacons from 'react-native-beacons-manager';
import moment from 'moment';

Expand All @@ -8,6 +9,10 @@ class beaconRangingOnly extends Component {
constructor(props) {
super(props);

this.beaconsEmitter = new NativeEventEmitter(Beacons);
this.beaconsDidRangeEvent = null;
this.authStateDidRangeEvent = null;

this.state = {
// region information
uuid: '7b44b47b-52a1-5381-90c2-f09b6838c5d4',
Expand All @@ -24,7 +29,7 @@ class beaconRangingOnly extends Component {
//

// OPTIONAL: listen to authorization change
DeviceEventEmitter.addListener(
this.authStateDidRangeEvent = this.beaconsEmitter.addListener(
'authorizationStatusDidChange',
(info) => console.log('authorizationStatusDidChange: ', info)
);
Expand All @@ -47,7 +52,7 @@ class beaconRangingOnly extends Component {
//

// Ranging: Listen for beacon changes
DeviceEventEmitter.addListener(
this.beaconsDidRangeEvent = this.beaconsEmitter.addListener(
'beaconsDidRange',
(data) => {
// console.log('beaconsDidRange data: ', data);
Expand All @@ -62,7 +67,8 @@ class beaconRangingOnly extends Component {
// stop ranging beacons:
Beacons.stopRangingBeaconsInRegion(region);
// remove beacons event we registered at componentDidMount
DeviceEventEmitter.removeListener('beaconsDidRange');
this.beaconsDidRangeEvent.remove();
this.authStateDidRangeEvent.remove();
}

render() {
Expand Down
4 changes: 3 additions & 1 deletion ios/RNiBeacon/RNiBeacon/RNiBeacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
//

#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RNiBeacon : NSObject <RCTBridgeModule>
@interface RNiBeacon : RCTEventEmitter <RCTBridgeModule>

@end
42 changes: 35 additions & 7 deletions ios/RNiBeacon/RNiBeacon/RNiBeacon.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ @implementation RNiBeacon

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

#pragma mark Initialization

- (instancetype)init
Expand All @@ -42,6 +40,17 @@ - (instancetype)init
return self;
}

- (NSArray<NSString *> *)supportedEvents
{
return @[
@"authorizationStatusDidChange",
@"beaconsDidRange",
@"regionDidEnter",
@"regionDidExit",
@"didDetermineState"
];
}

#pragma mark

-(CLBeaconRegion *) createBeaconRegion: (NSString *) identifier
Expand Down Expand Up @@ -207,8 +216,8 @@ -(NSString *)nameForAuthorizationStatus:(CLAuthorizationStatus)authorizationStat

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
NSString *statusName = [self nameForAuthorizationStatus:status];
[self.bridge.eventDispatcher sendDeviceEventWithName:@"authorizationStatusDidChange" body:statusName];
NSString *statusName = [self nameForAuthorizationStatus:status];
[self sendEventWithName:@"authorizationStatusDidChange" body:statusName];
}

-(void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error
Expand All @@ -224,6 +233,25 @@ -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)
NSLog(@"Location manager failed: %@", error);
}

-(NSString *)stringForState:(CLRegionState)state {
switch (state) {
case CLRegionStateInside: return @"inside";
case CLRegionStateOutside: return @"outside";
case CLRegionStateUnknown: return @"unknown";
default: return @"unknown";
}
}

- (void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
NSDictionary *event = @{
@"state": [self stringForState:state],
@"identifier": region.identifier,
};

[self sendEventWithName:@"didDetermineState" body:event];
}

-(void) locationManager:(CLLocationManager *)manager didRangeBeacons:
(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
Expand Down Expand Up @@ -252,7 +280,7 @@ -(void) locationManager:(CLLocationManager *)manager didRangeBeacons:
@"beacons": beaconArray
};

[self.bridge.eventDispatcher sendDeviceEventWithName:@"beaconsDidRange" body:event];
[self sendEventWithName:@"beaconsDidRange" body:event];
}

-(void)locationManager:(CLLocationManager *)manager
Expand All @@ -262,7 +290,7 @@ -(void)locationManager:(CLLocationManager *)manager
@"uuid": [region.proximityUUID UUIDString],
};

[self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidEnter" body:event];
[self sendEventWithName:@"regionDidEnter" body:event];
}

-(void)locationManager:(CLLocationManager *)manager
Expand All @@ -272,7 +300,7 @@ -(void)locationManager:(CLLocationManager *)manager
@"uuid": [region.proximityUUID UUIDString],
};

[self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidExit" body:event];
[self sendEventWithName:@"regionDidExit" body:event];
}


Expand Down
Loading