IBeacon background monitoring [closed]

牧云@^-^@ 提交于 2021-02-08 10:14:50

问题


I'm building an app which's core functionality requires beacon monitoring. To be exact I need to add the payload (min range) value of every beacon with a specific UUID to a Core Data list(it would be even better if I could set a certain threshold of time in which the beacon needs to stay in reach before it gets added to the list). I've been looking for solutions, but it's a bit of a version mess and I can not really tell if what I need is possible. I've found this article, according to which I can get an event triggered in the background, or use Background Modes. My question is if this is still true and if so if anybody has resources concerning the use of Background Models combined with IBeacon.

Greets from Germany!


回答1:


Apple restricts the duration in which iOS apps may "range" beacons in the background. This is true as of April 2020, and the state of affairs is largely unchanged in the last 5-6 years.

A few clarifications:

  1. Beacon monitoring is not restricted in the background, provided the user grants "location always" permission to the app. But beacon monitoring only gives you "entry" and "exit" events. It gives you an entry event when any beacon you are looking for first appears, and an exit event when the last of the beacons you are looking for disappears. Monitoring won't tell you anything about the estimated distance or signal strength of an individual beacon.

  2. Beacon ranging lets you get updates every second with a list of all beacons visible, each beacon's signal strength and a distance estimate. You can easily program logic to write to a database if the distance estimate is under as certain threshold.

  3. Beacon ranging is restricted in the background on iOS. First, the user must grant "location always" access to your app. And even then you are limited to about 5-10 seconds of ranging after your app goes to a background, or beacons first appear after it is in the background.

  4. You can extend the 5-10 seconds mentioned in (3) to 180 seconds simply by running a background task per my blog post here.

  5. You can further extend the 180 seconds indefinitely if you declare "location" background mode in your Info.plist, use a background task as described in (4), and you use CoreLocation to request location updates (coarse location updates with only a 3km resolution work fine for this purpose and save battery by keeping the GPS off.)

  6. One problem with (5) is that it may get your app rejected if you plan to submit it to the App Store and you don't provide an obvious user-facing benefit to using location in the background. If you do have a good justification, or you intend to distribute the app outside the App Store (e.g. a corporate enterprise app), then this will work fine.

  7. A second problem with (5) is that ranging all the time can cause significant battery drain. You may need to program extra logic to stop this constant background ranging at times where it is not needed in order to save battery.

This is admittedly confusing and complex. But the bottom line is that there are ways to range beacons indefinitely to satisfy many use cases. You just have to jump through some hoops to make it happen.



来源:https://stackoverflow.com/questions/61048707/ibeacon-background-monitoring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!