How to detect ibeacon device in background

妖精的绣舞 提交于 2019-12-08 08:34:53

问题


I am implementing notification-based ibeacon app. What I am trying to do is exactly same as the video(https://www.youtube.com/watch?v=SrsHBjzt2E8). A user download the app from Appstore, take a look and then push it background. Supposed the user was doing whole things at home. Later, the user walk around the store ibeacon installed while the app is in background mode.What I expected is that the app automatically detect ibeacon devices and get notified. However,region ranging and monitoring should be the first to detect beacon devices nearby in FOREGROUND. Thats the current limitation in IOS 7.

Does anyone have experience on how to detect ibeacon devices without letting a user bring the app into the foreground and click the button to start ranging and monitoring?..

Thanks


回答1:


You can use the CoreLocation beacon monitoring APIs to detect beacons in the background -- it works the same way as in the foreground, and is automatic. You don't need to do any special configuration to set it up.

The first time your app runs and sets up a monitoring region, it will be remembered by CoreLocation even after your phone reboots or your app is no longer in the foreground. Your app will then be launched into the background for about 5 seconds when you enter or exit the region of a beacon, and it will get a callback to the didDetermineState: forRegion: method.

You can even do ranging in the background for this five second period, after which iOS will suspend your app again. This five second window is typically used to send a local notification to the user, so they can gesture to launch the application into the foreground if desired. This allows you to tell a user they are near a point of interest (triggered by being near the beacon) and then let them elect to get more information or interact with the app by tapping the local notification.

Be aware that background monitoring callbacks are not instantaneous. It can take up to 15 minutes to get a notification in the background. See here for details.



来源:https://stackoverflow.com/questions/23412517/how-to-detect-ibeacon-device-in-background

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