react-native -v): 0.39.0 BackgroundGeolocation.setConfig({
desiredAccuracy: 0,
stationaryRadius: 25,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_ERROR,
url: `${config.API_URL}location_tracking`,
headers: { authorization: `Bearer ${state.session.token}` }
}, status => {
if (!status.enabled) {
BackgroundGeolocation.start(null, capture)
}
}, capture)
So the problem is that the plugin keeps spawning an alert Sending '{eventName}' with no listeners registered while in dev. How can I hide that?
Where is this alert appearing? Is this a react amber warning at the bottom of your screen? Show me.
@christocracy Yes is that amber warning at the bottom:

I wrote this small hack to avoid showing the warnings:
const events = ['location', 'motionchange', 'activitychange', 'providerchange',
'geofence', 'geofenceschange', 'http', 'heartbeat', 'schedule']
events.forEach(event => BackgroundGeolocation.on(event, noop => noop))
Intersting tho is that I have logLeve: BackgroundGeolocation.LOG_LEVEL_ERROR configured as you can see. And no, I don't need listeners :-)
This warning is coming from RCTEventEmitter.
Are you not listening to any events? What's the point of using this plugin if you're not going to listen to anything??
LOG_LEVEL_ERROR has nothing to do with this. These warnings are coming from React Native, not directly from the plugin.
The plugin has no way to query RCTEventEmitter if there's no listeners for a given event.
There's no way to silence this warning without providing an event-listener for at least one of the plugin's events.
Got it, so I'll add at least an event for error. I'm not listening for any event in app because I'm using RNBackgroundGeolocation just for the background task, my app don't need that info just my server.
I had the same issue which was really bugging me. If Remote JS Debugging is on then every reload got me the warning which I had to dismiss to get to my bottom NAV bar for testing.
Thanks to the note above I added this to componentDidMount and they're finally gone:
// Hide a warning about something we dont use:
// https://github.com/transistorsoft/react-native-background-geolocation/issues/242
const events = ['providerchange',];
events.forEach(event => this.props.geolocator.on(event, noop => noop));
I'd suggest that something along these lines be added to the docs.
Though I attached listeners yet I am getting this warning message
````
constructor(props) {
super(props);
this.state = {
....
}
this.onLocation = this.onLocation.bind(this);
this.onError = this.onError.bind(this);
this.onActivityChange = this.onActivityChange.bind(this);
this.onProviderChange = this.onProviderChange.bind(this);
this.onMotionChange = this.onMotionChange.bind(this);
}
componentWillUnmount() {
BackgroundGeolocation.removeListeners();
}
async componentDidMount(){
// This handler fires whenever bgGeo receives a location update.
BackgroundGeolocation.onLocation(this.onLocation, this.onError);
// This handler fires when movement states changes (stationary->moving; moving->stationary)
BackgroundGeolocation.onMotionChange(this.onMotionChange);
// This event fires when a change in motion activity is detected
BackgroundGeolocation.onActivityChange(this.onActivityChange);
// This event fires when the user toggles location-services authorization
BackgroundGeolocation.onProviderChange(this.onProviderChange);
////
// 2. Execute #ready method (required)
//
BackgroundGeolocation.ready({
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 1,
// Application config
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: true, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
// HTTP / SQLite config
url: 'http://yourserver.com/locations',
batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
headers: { // <-- Optional HTTP headers
"X-FOO": "bar"
},
params: { // <-- Optional HTTP params
"auth_token": "maybe_your_server_authenticates_via_token_YES?"
}
}, (state) => {
console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
if (!state.enabled) {
////
// 3. Start tracking!
//
BackgroundGeolocation.start(function() {
console.log("- Start success");
this.setState({ start: true })
});
}
});
}
onLocation(location) {
console.log('[location] -', location);
....
}
onError(error) {
console.warn('[location] ERROR -', error);
}
onActivityChange(event) {
console.log('[activitychange] -', event); // eg: 'on_foot', 'still', 'in_vehicle'
}
onProviderChange(provider) {
console.log('[providerchange] -', provider.enabled, provider.status);
}
onMotionChange(event) {
console.log('[motionchange] -', event.isMoving, event.location);
}
````
Most helpful comment
I had the same issue which was really bugging me. If Remote JS Debugging is on then every reload got me the warning which I had to dismiss to get to my bottom NAV bar for testing.
Thanks to the note above I added this to componentDidMount and they're finally gone:
I'd suggest that something along these lines be added to the docs.