react-native-beacons-manager
react-native-beacons-manager copied to clipboard
Beacons.BeaconsEventEmitter.addListener - undefined is not an object
Version
"react": "16.4.1", "react-native": "0.56.0", "react-native-beacons-manager": "^1.0.7"
Platform
iOS | Android
Steps to reproduce
- fresh new app with react-native init
- install package
- in componentDidMount:
if (Platform.OS == 'ios') {
Beacons.requestAlwaysAuthorization();
Beacons.startMonitoringForRegion(region)
.then(() => console.log('Beacons monitoring started succesfully'))
.catch(error => console.log(`Beacons monitoring not started, error: ${error}`));
Beacons.startUpdatingLocation();
// Monitoring: Listen for device entering the defined region
this.regionDidEnterEvent = Beacons.BeaconsEventEmitter.addListener(
'regionDidEnter',
(data) => {
console.log('monitoring - regionDidEnter data: ', data);
const time = moment().format(TIME_FORMAT);
this.setState({ regionEnterDatasource: this.state.rangingDataSource.cloneWithRows([{ identifier:data.identifier, uuid:data.uuid, minor:data.minor, major:data.major, time }]) });
}
);
// Monitoring: Listen for device leaving the defined region
this.regionDidExitEvent = Beacons.BeaconsEventEmitter.addListener(
'regionDidExit',
({ identifier, uuid, minor, major }) => {
console.log('monitoring - regionDidExit data: ', { identifier, uuid, minor, major });
const time = moment().format(TIME_FORMAT);
this.setState({ regionExitDatasource: this.state.rangingDataSource.cloneWithRows([{ identifier, uuid, minor, major, time }]) });
}
);
}
What is happening
An Error shows running on device (and emulator for that matter):
TypeError: undefined is not an object (evaluating '_reactNativeBeaconsManager.default.BeaconsEventEmitter.addListener')
While Beacons.BeaconsEventEmitter is present in the examples shown here, should I use DeviceEventEmitter instead?
Yes you should use DeviceEventEmitter. Got same issue, resolved by replacing Beacons.BeaconsEventEmitter.addListener with DeviceEventEmitter.addListener.
Beacons.BeaconsEventEmitter.addListener
only works on 1.1.0 version. See #103 to install 1.1.0 version from master
@daominhsangvn @RajaSaravanan DeviceEventEmitter.addListener is not working in android, could you please help me?
You can use DeviceEventEmitter.addListener
instead of Beacons.BeaconsEventEmitter.addListener