New to React Native. I’m building an app and would like to integrate a feature that lets it interact with Estimote Beacons. I’m using this library I found from the Estimote website (https://github.com/Estimote/react-native-proximity/) and integrated it into my App.js file. I can go past the locationPermission.request()
part but it throws an error on the RNEP.proximityObserver.initialize()
line. The error message is:
[Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNEstimoteProximity.initialize')]
- node_modules\@estimote\react-native-proximity\index.js:67:33 in <global>
- node_modules\promise\setimmediate\core.js:37:14 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:25 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:146:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:194:17 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:458:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:407:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:142:17 in __guard$argument_0
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue
My App.js code:
import React, {useState} from 'react';
import * as Font from 'expo-font';
import { AppLoading } from 'expo';
import Navigator from './routes/drawer';
import * as RNEP from '@estimote/react-native-proximity';
const startProximityObserver = () => {
const ESTIMOTE_APP_ID = "XXXXXXXXXXXXXXX";
const ESTIMOTE_APP_TOKEN = "XXXXXXXXXXXXXXX";
const zone1 = new RNEP.ProximityZone(5, "va-test");
zone1.onEnterAction = context => {
console.log("zone1 onEnter", context);
};
zone1.onExitAction = context => {
console.log("zone1 onExit", context);
};
zone1.onChangeAction = contexts => {
console.log("zone1 onChange", contexts);
};
RNEP.locationPermission.request().then(
permission => {
console.log(`location permission: ${permission}`);
if (permission !== RNEP.locationPermission.DENIED) {
const credentials = new RNEP.CloudCredentials(
ESTIMOTE_APP_ID,
ESTIMOTE_APP_TOKEN
);
const config = {
notification: {
title: "Exploration mode is on",
text: "We'll notify you when you're next to something interesting.",
channel: {
id: "exploration-mode",
name: "Exploration Mode"
}
}
};
RNEP.proximityObserver.initialize(credentials, config);
RNEP.proximityObserver.startObservingZones([zone1]);
}
},
error => {
console.error("Error when trying to obtain location permission", error);
}
);
};
const stopProximityObserver = () => { RNEP.proximityObserver.stopObservingZones(); };
const getFonts = () => Font.loadAsync({
'regular' : require('./assets/fonts/Poppins-Regular.ttf'),
'semibold' : require('./assets/fonts/Poppins-SemiBold.ttf'),
'light' : require('./assets/fonts/Poppins-Light.ttf')
});
startProximityObserver();
export default function App() {
const [fontsLoaded, setFontsLoaded] = useState(false);
if(fontsLoaded) {
return (
<Navigator />
);
} else {
return (
<AppLoading startAsync={getFonts} onFinish={() => setFontsLoaded(true)} />
)
}
}
I double-checked my Estimote App ID and App Token and they’re correct, so I have no idea why the initialize function isn’t working. I tried looking at their forums but I haven’t found anything useful. Am I missing something else in the code?