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 duplicate interface definition RTBridge #52

Open
wants to merge 5 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions RNBeacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// Copyright (c) 2015 Geniux Consulting. All rights reserved.
//

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

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

@end
@end
67 changes: 42 additions & 25 deletions RNBeacon.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <CoreLocation/CoreLocation.h>

#import "RCTBridge.h"
//#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"

Expand All @@ -29,16 +29,26 @@ @implementation RNBeacon

#pragma mark Initialization

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



- (instancetype)init
{
if (self = [super init]) {
self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
self.dropEmptyRanges = NO;
}

return self;
}

Expand All @@ -47,38 +57,38 @@ - (instancetype)init
- (CLBeaconRegion *) createBeaconRegion: (NSString *) identifier uuid: (NSString *) uuid major: (NSInteger) major minor:(NSInteger) minor
{
NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:uuid];

unsigned short mj = (unsigned short) major;
unsigned short mi = (unsigned short) minor;

CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID major:mj minor:mi identifier:identifier];

beaconRegion.notifyEntryStateOnDisplay = YES;

return beaconRegion;
}

- (CLBeaconRegion *) createBeaconRegion: (NSString *) identifier uuid: (NSString *) uuid major: (NSInteger) major
{
NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:uuid];

unsigned short mj = (unsigned short) major;

CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID major:mj identifier:identifier];

beaconRegion.notifyEntryStateOnDisplay = YES;

return beaconRegion;
}

- (CLBeaconRegion *) createBeaconRegion: (NSString *) identifier uuid: (NSString *) uuid
{
NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:uuid];

CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID identifier:identifier];

beaconRegion.notifyEntryStateOnDisplay = YES;

return beaconRegion;
}

Expand Down Expand Up @@ -147,6 +157,9 @@ - (NSString *)stringForProximity:(CLProximity)proximity {

RCT_EXPORT_METHOD(startUpdatingLocation)
{
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
[_locationManager setAllowsBackgroundLocationUpdates:YES];
}
[self.locationManager startUpdatingLocation];
}

Expand Down Expand Up @@ -183,11 +196,11 @@ -(NSString *)nameForAuthorizationStatus:(CLAuthorizationStatus)authorizationStat
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
NSString *statusName = [self nameForAuthorizationStatus:status];
[self.bridge.eventDispatcher sendDeviceEventWithName:@"authorizationStatusDidChange" body:statusName];
[self sendEventWithName:@"authorizationStatusDidChange" body:statusName];
}

- (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error
{
{
NSLog(@"Failed ranging region: %@", error);
}

Expand All @@ -206,28 +219,28 @@ -(void) locationManager:(CLLocationManager *)manager didRangeBeacons:
return;
}
NSMutableArray *beaconArray = [[NSMutableArray alloc] init];

for (CLBeacon *beacon in beacons) {
[beaconArray addObject:@{
@"uuid": [beacon.proximityUUID UUIDString],
@"major": beacon.major,
@"minor": beacon.minor,

@"rssi": [NSNumber numberWithLong:beacon.rssi],
@"proximity": [self stringForProximity: beacon.proximity],
@"accuracy": [NSNumber numberWithDouble: beacon.accuracy]
}];
}

NSDictionary *event = @{
@"region": @{
@"identifier": region.identifier,
@"uuid": [region.proximityUUID UUIDString],
},
@"beacons": beaconArray
};
[self.bridge.eventDispatcher sendDeviceEventWithName:@"beaconsDidRange" body:event];

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

-(void)locationManager:(CLLocationManager *)manager
Expand All @@ -236,8 +249,8 @@ -(void)locationManager:(CLLocationManager *)manager
@"region": region.identifier,
@"uuid": [region.proximityUUID UUIDString],
};
[self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidEnter" body:event];

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

-(void)locationManager:(CLLocationManager *)manager
Expand All @@ -246,8 +259,12 @@ -(void)locationManager:(CLLocationManager *)manager
@"region": region.identifier,
@"uuid": [region.proximityUUID UUIDString],
};

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

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

- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations {
}

@end