react-native-beacons-manager icon indicating copy to clipboard operation
react-native-beacons-manager copied to clipboard

Detected Beacons suddenly disappears

Open drailanjohngss opened this issue 8 years ago • 1 comments

Version

1.0.1

Platform

iOS | Android

OS version

iOS 10| android 7.0...

Steps to reproduce

Scenario

  • Our app aims to detect beacons placed inside the restaurants our app uses react-native-beacons-manager
  • When our app detects a beacon, I have developed a cloud function that accepts the beacon's major key and use it to query data of that restaurant from my database
  • The Cloud function then sends a push notification on the user about the restaurant details.

The problem The way I detect the beacons is not stable. this is my flow. I created a function located at

this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
   //function-here 
); 

I can receive the beacons information like uuid, major and minor key and proximity (immediate, near, far, unknown) . Now inside that function I use the major key to determine the individuality of each beacons. Now, I've made a condition like this:

 let beaconArr = data.beacons;
        console.log(beaconArr);
        console.log(count);
        if (beaconArr.length > 0) {
          console.log("beacons detected!");
          let major = data.beacons[0].major;
          let prox = data.beacons[0].proximity;

          if ((prox === "near" || prox === "far") && beaconFlag === false && count === 0) {
            console.log("beacon Action");
            this.props.beaconAction(major);
            this.props.createCheckInHistory(user.uid);
            beaconFlag = true;
            count++;
          } else {
            console.log("counter turned to 1!");
            console.log(data);
            beaconFlag = true;
          }
        } else {
          console.log("no beacons detected!");
          count = 0;
          beaconFlag = false;
        }

Expected behavior

I expect that the functions inside the condition is true will only fire once. Beacons should constantly range detected beacons when the app is opened.

Actual behavior

Sometimes, its ok sometimes its not. even if im still at the range of the beacon, suddenly the beacon's array got 0. Then suddenly i'll receive a push notification again and again. Detected beacons suddenly disappears, and sometimes comebacks again. image

This is my full componentDidMount() code:

componentDidMount() {
    this.props.selectedIcon('map');

    firebase
      .messaging()
      .getInitialNotification()
      .then(notification => {
        console.log("Notification which opened the app: ", notification);
      });

    const user = firebase.auth().currentUser;
    let count = 0;
    let beaconFlag = false;
    //  will be set as a reference to "regionDidEnter" event:
    this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
      "beaconsDidRange",
      _.throttle(data => {
        let beaconArr = data.beacons;
        console.log(beaconArr);
        console.log(count);
        if (beaconArr.length > 0) {
          console.log("beacons detected!");
          let major = data.beacons[0].major;
          let prox = data.beacons[0].proximity;

          if ((prox === "near" || prox === "far") && beaconFlag === false && count === 0) {
            console.log("beacon Action");
            this.props.beaconAction(major);
            this.props.createCheckInHistory(user.uid);
            beaconFlag = true;
            count++;
          } else {
            console.log("counter turned to 1!");
            console.log(data);
            beaconFlag = true;
          }
        } else {
          console.log("no beacons detected!");
          count = 0;
          beaconFlag = false;
        }
      }, 3000)
    );

    // monitoring events
    this.regionDidEnterEvent = Beacons.BeaconsEventEmitter.addListener(
      "regionDidEnter",
      data => {
        console.log("monitoring - regionDidEnter data: ", data);
      }
    );

    // Monitoring: Listen for device leaving the defined region
    this.regionDidExitEvent = Beacons.BeaconsEventEmitter.addListener(
      "regionDidExit",
      data => {
        console.log("monitoring - regionDidExit data: ", data);
      }
    );
  }

drailanjohngss avatar Apr 25 '18 03:04 drailanjohngss

Hello @drailanjohngss, could you please tell were you able to figure out how to solve this issue? Thanks

sergei-zelinsky avatar Feb 17 '21 19:02 sergei-zelinsky