1

I'm currently working on an app that I want for my app to detect a beacon in background mode just when it gets close to it(Immediate). Based on articles that I've read it cannot be done with didEnterRegion and I should use ranging while it's running in the background mode(Location Update). is there any solution that directly reduces the didEnterRegion threshold? or Should I use the other method? and if that's the case does it work like didEnterRegion but with a limited range of RSSI? does it work when my phone entered the region and it's locked and the screen is off?

fafa92
  • 143
  • 1
  • 12

1 Answers1

4

Monitoring APIs give you no control over the distance at which you get detection callbacks. You always get a callback the first time a beacon goes within radio range, typically at around 40 meters.

There are two ways to trigger on beacons only at close range:

  1. Configure a lower radio transmission power on your beacon, if the manufacturer supports it.

  2. Combine Ranging APIs with Monitoring, and range for as long as possible in the background (180 secs max on iOS without special background permissions), then trigger your logic when a ranging callback says the CLBeacon accuracy field is immediate.

Option 1 is simpler, but less reliable as it will often trigger at greater distances than you'd like and sometimes has trouble triggering at all even at extremely close range.

Option 2 is more reliable, so long as background ranging time does not run out. If a phone's radio triggers at 40 meters to start ranging, if the user takes more than 180 secs to get to immediate proximity then ranging time runs out and you are unable to get a trigger until the beacon disappears and reappears to reset the ranging time allowed.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thanks for your clarification, so as I understood there is no way to do ranging for a long-term without any turning off? even by triggering location updates like this line: self.locationManager.allowsBackgroundLocationUpdates = true; – fafa92 Jun 22 '17 at 15:53
  • Can turning cellphone's screen on by pressing shoulder button or home button be considered as a trigger for iOS to start ranging again? or it just can be restarted when phone get out of range and then entered? – fafa92 Jun 22 '17 at 21:23
  • 1
    Yes it can. There is a setting on CLBeaconRegion called notifyEntryStateOnDisplay that will cause an extra callback which will reset the clock on ranging. The allowsBackgroundLocationUpdates setting has no effect on beacon ranging, but you can add the location background mode to your plist to get unlimited background ranging. Thanks problem there is that you need to convince Apple you are offering a compelling location-related benefit to users to get approval for the app store. – davidgyoung Jun 23 '17 at 03:43
  • Thanks a lot David, I'm not sure If I got it right, please correct me if I'm wrong, as you said, we can just set notifyEntryStateOnDisplay for our CLBeaconRegion and not set the app as the way to scan whole the time in the background(allowsBackgroundLocationUpdates) which leads to an app blocking by Apple. So if the user turns on his screen by his choice ranging will be enabled and also it's in a line with Apple's policies, is that right? – fafa92 Jun 23 '17 at 06:31
  • Correct. Ranging will be enabled for the allowed time starting when the screen is illuminated – davidgyoung Jun 23 '17 at 14:20