Hi, great project! It would be awesome if Bluetooth beacons and geo fences would be implemented. I noticed it’s on the radar (iBeacon support).
I’ve did some testing where I created an Expo project and detached it with $ exp detach
.
Then, I’ve installed $ npm install react-native-beacons-manager --save
, ran $ react-native link
and updated the build gradle as described here, https://docs.expo.io/versions/v15.0.0/guides/expokit.html:
Note: You may have to update android/app/build.gradle after running react-native link. Change the line added by react-native link from compile project(‘:library-name’) to compile(project(‘:library-name’)) { exclude module: ‘react-native’ }.
In main.js I’ve added DeviceEventEmitter
to the third line:
import { Platform, StatusBar, StyleSheet, View, DeviceEventEmitter } from 'react-native';
And below the imports I’ve added this code:
import Beacons from 'react-native-beacons-manager';
// Tells the library to detect iBeacons
Beacons.detectIBeacons();
// Monitoring
try {
const myRegion = {
identifier: 'BEACON',
uuid: 'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
minor: 54480,
major: 10004
};
Beacons.startMonitoringForRegion(myRegion);
console.log('Beacons monitoring started successfully');
} catch (err) {
console.log('Beacons monitoring not started, error: ${err}');
}
DeviceEventEmitter.addListener('regionDidEnter', (region) => {
console.log('regionDidEnter!', region);
});
DeviceEventEmitter.addListener('regionDidExit', (region) => {
console.log('regionDidExit!', region);
});
All seems to work fine and I get the console.log Beacons monitoring started successfully, however, DeviceEventEmitter.addListener('regionDidEnter', ...);
is never fired.
When I run the same code in a fresh non-Expo project (with react-native init
) the listeners are triggered as expected. I understand detach
is an alpha feature, so maybe it’s an issue or maybe I’m missing something