Closed erikhuisman closed 1 year ago
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'}
}
);
A method
requestStateForRegion
and eventdidDetermineState
to request the initial/current state of a beacon region. I can do a PR some time soon