Question

I cannot understand the use of didDetermineStateForRegion(int state, Region region) in ibeaconSevice library.

I have a service that runs in background mode, when I see a beacon for the first time both didEnterRegion(Region region) and didDetermineStateForRegion(int state, Region region) are called. Then the scan is stopped. In the next Scan no callback is performed even though I am still in the same region. Please, could you help?

iBeaconManager.setBackgroundMode(this, true);
iBeaconManager.setBackgroundMode(this, true);    
     iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
      @Override
      public void didEnterRegion(Region region) {
      Log.d(ConstantsDecoder.LOGTAG, "I just saw an iBeacon for the first time!"); 
}


@Override
public void didDetermineStateForRegion(int state, Region region) {
                Log.d(ConstantsDecoder.LOGTAG, "I have just switched from   seeing/not seeing iBeacons: "+state); 

            }
Was it helpful?

Solution

These methods only get called once for each state change. So it works like this:

  1. An iBeacon becomes visible to the device.

  2. didEnterRegion and didDetermineStateForRegion get called.

  3. No more calls are made to the above methods while the iBeacon is visible to the device.

  4. The iBeacon is no longer visible to the device.

  5. didExitRegion and didDetermineStateForRegion get called.

  6. No more calls are made to the above methods while the iBeacon is not visible to the device.

  7. Go to step 1.

If you want to get a call once per second with a list of all iBeacons that are being seen, use the Ranging Example Code here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top