From 24d3910e957a7959534ffae37095d7e105fce8f2 Mon Sep 17 00:00:00 2001 From: sriky Date: Tue, 18 Apr 2017 11:01:14 +0300 Subject: [PATCH 1/5] Fix duplicate interface definition RTBridge --- RNBeacon.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNBeacon.m b/RNBeacon.m index 4faf0df..4ac0d6c 100644 --- a/RNBeacon.m +++ b/RNBeacon.m @@ -8,7 +8,7 @@ #import -#import "RCTBridge.h" +//#import "RCTBridge.h" #import "RCTConvert.h" #import "RCTEventDispatcher.h" From 1750003fbfb7e40d4abeedaf6762a4c2dc424152 Mon Sep 17 00:00:00 2001 From: sriky Date: Fri, 4 Aug 2017 11:07:21 +0300 Subject: [PATCH 2/5] allowsBackgroundLocationUpdates flag to YES --- RNBeacon.m | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/RNBeacon.m b/RNBeacon.m index 4ac0d6c..8b12d21 100644 --- a/RNBeacon.m +++ b/RNBeacon.m @@ -33,12 +33,12 @@ - (instancetype)init { if (self = [super init]) { self.locationManager = [[CLLocationManager alloc] init]; - + self.locationManager.delegate = self; self.locationManager.pausesLocationUpdatesAutomatically = NO; self.dropEmptyRanges = NO; } - + return self; } @@ -47,38 +47,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; } @@ -147,6 +147,9 @@ - (NSString *)stringForProximity:(CLProximity)proximity { RCT_EXPORT_METHOD(startUpdatingLocation) { + if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) { + [_locationManager setAllowsBackgroundLocationUpdates:YES]; + } [self.locationManager startUpdatingLocation]; } @@ -187,7 +190,7 @@ -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus } - (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error -{ +{ NSLog(@"Failed ranging region: %@", error); } @@ -206,19 +209,19 @@ -(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, @@ -226,7 +229,7 @@ -(void) locationManager:(CLLocationManager *)manager didRangeBeacons: }, @"beacons": beaconArray }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"beaconsDidRange" body:event]; } @@ -236,7 +239,7 @@ -(void)locationManager:(CLLocationManager *)manager @"region": region.identifier, @"uuid": [region.proximityUUID UUIDString], }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidEnter" body:event]; } @@ -246,7 +249,7 @@ -(void)locationManager:(CLLocationManager *)manager @"region": region.identifier, @"uuid": [region.proximityUUID UUIDString], }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidExit" body:event]; } From d0f42eea79ce2d319f085788ac5a76fcaf899d4b Mon Sep 17 00:00:00 2001 From: sriky Date: Fri, 4 Aug 2017 14:11:26 +0300 Subject: [PATCH 3/5] Adding callback for the location updates --- RNBeacon.m | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/RNBeacon.m b/RNBeacon.m index 8b12d21..efd963d 100644 --- a/RNBeacon.m +++ b/RNBeacon.m @@ -33,12 +33,12 @@ - (instancetype)init { if (self = [super init]) { self.locationManager = [[CLLocationManager alloc] init]; - + self.locationManager.delegate = self; self.locationManager.pausesLocationUpdatesAutomatically = NO; self.dropEmptyRanges = NO; } - + return self; } @@ -47,38 +47,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; } @@ -148,7 +148,7 @@ - (NSString *)stringForProximity:(CLProximity)proximity { RCT_EXPORT_METHOD(startUpdatingLocation) { if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) { - [_locationManager setAllowsBackgroundLocationUpdates:YES]; + [_locationManager setAllowsBackgroundLocationUpdates:YES]; } [self.locationManager startUpdatingLocation]; } @@ -190,7 +190,7 @@ -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus } - (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error -{ +{ NSLog(@"Failed ranging region: %@", error); } @@ -209,19 +209,19 @@ -(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, @@ -229,7 +229,7 @@ -(void) locationManager:(CLLocationManager *)manager didRangeBeacons: }, @"beacons": beaconArray }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"beaconsDidRange" body:event]; } @@ -239,7 +239,7 @@ -(void)locationManager:(CLLocationManager *)manager @"region": region.identifier, @"uuid": [region.proximityUUID UUIDString], }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidEnter" body:event]; } @@ -249,8 +249,12 @@ -(void)locationManager:(CLLocationManager *)manager @"region": region.identifier, @"uuid": [region.proximityUUID UUIDString], }; - + [self.bridge.eventDispatcher sendDeviceEventWithName:@"regionDidExit" body:event]; } +- (void)locationManager:(CLLocationManager *)manager + didUpdateLocations:(NSArray *)locations { +} + @end From 44650cd0f9944156e8aec39cb106174a47deb95f Mon Sep 17 00:00:00 2001 From: sriky Date: Tue, 12 Sep 2017 14:33:44 +0300 Subject: [PATCH 4/5] Fixing the RCTBridgeModule import --- RNBeacon.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RNBeacon.h b/RNBeacon.h index 2f8b2ca..31d537f 100644 --- a/RNBeacon.h +++ b/RNBeacon.h @@ -6,8 +6,8 @@ // Copyright (c) 2015 Geniux Consulting. All rights reserved. // -#import "RCTBridgeModule.h" +#import @interface RNBeacon : NSObject -@end \ No newline at end of file +@end From 459d0860723de30edc7fe4d08cc8352b9088652b Mon Sep 17 00:00:00 2001 From: sriky Date: Mon, 19 Mar 2018 07:02:24 +0200 Subject: [PATCH 5/5] Inheriting from RCTEventEmitter instead NSObject DeviceEventEmitter has been deprecated --- RNBeacon.h | 3 ++- RNBeacon.m | 58 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/RNBeacon.h b/RNBeacon.h index 31d537f..a201977 100644 --- a/RNBeacon.h +++ b/RNBeacon.h @@ -7,7 +7,8 @@ // #import +#import -@interface RNBeacon : NSObject +@interface RNBeacon : RCTEventEmitter @end diff --git a/RNBeacon.m b/RNBeacon.m index efd963d..b4f5b7e 100644 --- a/RNBeacon.m +++ b/RNBeacon.m @@ -29,16 +29,26 @@ @implementation RNBeacon #pragma mark Initialization +- (NSArray *)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; } @@ -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; } @@ -186,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); } @@ -209,19 +219,19 @@ -(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, @@ -229,8 +239,8 @@ -(void) locationManager:(CLLocationManager *)manager didRangeBeacons: }, @"beacons": beaconArray }; - - [self.bridge.eventDispatcher sendDeviceEventWithName:@"beaconsDidRange" body:event]; + + [self sendEventWithName:@"beaconsDidRange" body:event]; } -(void)locationManager:(CLLocationManager *)manager @@ -239,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 @@ -249,8 +259,8 @@ -(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