react-native-ibeacon icon indicating copy to clipboard operation
react-native-ibeacon copied to clipboard

Add requestStateForRegion / didDetermineState

Open erikhuisman opened this issue 9 years ago • 1 comments

A method requestStateForRegion and event didDetermineState to request the initial/current state of a beacon region. I can do a PR some time soon

erikhuisman avatar Jun 22 '15 21:06 erikhuisman

I added this code to RNBeacon.m; So far it works fine.

RCT_EXPORT_METHOD(requestStateForRegion:(NSDictionary *)dict) {
    [self.locationManager requestStateForRegion:[self convertDictToBeaconRegion:dict]];
}

-(void)locationManager:(CLLocationManager *)manager
     didDetermineState:(CLRegionState)state
             forRegion:(nonnull CLRegion *)region {
    CLBeaconRegion *beaconRegion = (CLBeaconRegion *) region;
    NSDictionary *event = @{
                            @"region": region.identifier,
                            @"uuid": [beaconRegion.proximityUUID UUIDString],
                            };

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

You can then call this and listen to the result in your JS like this:

const region = {
    identifier: 'your identifier',
    uuid: 'your uuid'
};

iBeacon.requestStateForRegion(region);
this.determineStateForRegionSubscription = DeviceEventEmitter.addListener(
        'didDetermineStateForRegion',
        data => {
            // Do what you want with 'data' {region: 'your region identifier', uuid: 'your region uuid'}
        }
);

fkattan avatar May 24 '16 20:05 fkattan