eddieowens / react-native-boundary

Native implementation of geofencing/region monitoring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Events.ENTER and Events.EXIT callbacks not being fired on IOS or Android

AkshitSahani opened this issue · comments

Hi Eddie, I have followed the exact instructions provided by you for setup. I have also confirmed that all the steps for iOS and Android manual linking are present in my application. However, the callbacks I am providing to the ENTER and EXIT events are not being fired. I get successful logs for setting up the geofence, but any of the logs or callbacks within the on ENTER and EXIT events are not fired.

The only thing I have been able to see (only on Android) is if I am already inside the boundary, the ENTER event is called. But when I exit the boundary, the EXIT event is not called, and neither is the ENTER event on re-entering. And since iOS has limitation of ENTER not being called if you are already inside the location, I have not been able to trigger any events on iOS.

To test, we are generating iOS and Android builds, setting geofence for a point (lat,lng) 1km away from us. Then we are actually driving over to the the point and then driving back to the initial location 1km away. Radius in my code is 500m, but in no point during this entire process is the callback fired. And we are also ensuring to keep the application running in foreground at all times for both platforms.

Here is my code:

setGeoFences = async(responseServices) => {
const radius = 500;
responseServices.forEach((service) => {
if(service.work_location.latitude && service.work_location.longitude){
if(service.start_date <= fullDateToday && service.end_date >= fullDateToday){
console.log('date check successful! about to set geofence');
Boundary.add({ //async function
lat: parseFloat(service.work_location.latitude),
lng: parseFloat(service.work_location.longitude),
radius, // in meters
id: service.work_order_id,
})
.then(() => {
console.log("successfully set geofence!!!!");
Alert.alert(
'GEOFENCE SET!!!!!',
'SUCCESS!!!',
);
})
.catch(e => {
console.error("error in setting geofence!!!:(", e)
Alert.alert(
'GEOFENCE NOT SET',
'FAILURE!!!!',
);
});

    Boundary.on(Events.ENTER, ids => {
      // Prints 'Get out of my Chipotle!!'
      console.log('enterign boundary!!!!!!! IT WORKS!!!!!!!!!!');
      Alert.alert(
        'ENTERING BOUNDARY!!!!!!!',
        'IT WORKSS!!!',
      );
    });

    Boundary.on(Events.EXIT, ids => {
      // Prints 'Ya! You better get out of my Chipotle!!'
      console.log('leaving boundary!!!!!!! IT WORKS!!!!!!!!!!');
      Alert.alert(
        'EXITING BOUNDARY!!!!!!!',
        'IT WORKSS!!!',
      );
    });
  }
  else if(fullDateToday > service.end_date && service.geo_fence_set){
    console.log('Going to remove boundary!!!!');
    Boundary.remove(`${service.work_order_id}`)
      .then(() => {
        console.log('removed boundary for work order' + service.work_order_id);
        Alert.alert(
          'REMOVING BOUNDARY!!!!!!!',
          'successful!!!',
        );
      })
      .catch(e => {
        console.log(`Failed to delete workorder${service.work_order_id}`, e);
        Alert.alert(
          'REMOVING BOUNDARY!!!!!!!',
          'failed!!!',
        );
      })
  }
}

});
}

In my app, geofences need to be set for the location of "work orders" and workers will travel in and out of those locations, during which these callbacks need to be fired. This function is not within the componentDidMount of a screen, but rather called when the user's upcoming work orders are fetched and for each work order that is currently going on, I create a boundary around its lat lng values. In each case, I am seeing the log and alert for geofence set, but I am unable to get any enter/exit functionality to work except when I am already within the boundary on Android.

Please advise what I could be missing, or if there is anything incorrect with my code.

@edwinvrgs
Please look in this matter

Screen Shot 2019-04-02 at 5 23 27 PM
when i am already within the boundary on Android app crashed here is error log image
help me to solve this problem

@AkshitSahani have you tried disabling battery optimisation for your application? It may be related to this issue here #19

@nimeshbhalani7 please open a separate issue including the version of React Native Boundary you are using as well as your Android version and a stack trace.

@AkshitSahani what versions of Android and iOS are you using? Are you granting permission to use the location API in either OS? What version of React Native Boundary are you using?

@eddieowens I too am experiencing this problem. Boundaries are registered and will trip if I move in and out of a region, but the callbacks never fire and I receive a YellowBox warning stating
"Sending 'onEnter' with no listeners registered"

Im using:
iOS 12.1
Android 8.1
react-native-boundary 1.0.7
react-native 0.57.3

My test implementation is dead simple.

componentWillMount() {
  Boundary.on(Events.ENTER, () => console.log('Entered'));
  Boundary.on(Events.EXIT, () => console.log('Exited'));
}
componentWillUnmount() {
  Boundary.removeAll();
}

Any idea or direction would be appreciated.

@adammacdonald the issue was addressed by @mikaelengstrom in PR #29.

@AkshitSahani that PR may have addressed some confusion around the remove and removeAll functions in the library. I'm closing this issue due to inactivity but that doesn't mean there is no bug here. If you encounter the problem again, please just open another issue. Thanks!