简体   繁体   English

在信标周围花费时间

[英]Time spend around a beacon

What should be the correct approach to identify time spend around a beacon[not within a region] in background. 识别背景中信标周围(不在区域内)的时间的正确方法应该是什么。 I am able to do this when app is in foreground using didRangeBeacons and some business logic.I read on few forums that ranging does work when app has registered for location updates in background, but i am having no success. 当应用程序使用didRangeBeacons和一些业务逻辑在前台运行时,我能够做到这一点。我在一些论坛上读到,当应用程序在后台注册位置更新时,测距确实有效,但是我没有成功。 I have added the location updates key for UIBackgroundModes in plist. 我在plist中为UIBackgroundModes添加了位置更新键。

I am using estimote beacons and their sdk. 我正在使用estimote信标及其sdk。

I see two possible solutions here: 我在这里看到两个可能的解决方案:

  1. Listen for enter and exit region events, store the timestamps and then use them to calculate the time span on exit. 侦听进入和退出区域事件,存储时间戳,然后使用它们计算退出时的时间跨度。 If you define your region so that it encompasses only one beacon, monitoring the region will be equivalent to monitoring the beacon. 如果您将区域定义为仅包含一个信标,则监视该区域等同于监视该信标。 The only thing to keep in mind is that iOS imposes a limit of 20 regions to be monitored at the same time - so this solution doesn't scale above 20 beacons. 唯一要记住的是,iOS限制了同时要监视的20个区域的限制-因此此解决方案不能扩展到20个以上的信标。

  2. Use ranging in the background. 在后台使用范围。 Apart from the UIBackgroundModes , you also need to start regular location services, ie startUpdatingLocation . 除了UIBackgroundModes ,您还需要启动常规位置服务,即startUpdatingLocation

    Beacon ranging delivers events normally while an app is running in the foreground. 当应用程序在前台运行时,信标范围调整通常会传递事件。 When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app and the standard location service is running. 当您的应用程序在后台运行时,仅当该应用程序启用了位置更新后台模式且标准定位服务正在运行时,此服务才会传递事件。

    (this is from CLLocationManager class reference , section "Using Location Services in the Background") (这来自CLLocationManager类参考 ,“在后台使用位置服务”部分)

    Note that ranging in the background will be draining the battery life more than usual, and Apple also requires justification for using the background modes. 请注意,在后台进行测距将比平时消耗更多的电池寿命,并且Apple还要求使用后台模式的理由。 Unless there's some value for the user of your app coming from the background modes, they might choose to reject it. 除非应用程序的用户从后台模式获得了一些价值,否则他们可能会选择拒绝它。 All in all, use the background ranging wisely! 总而言之,明智地使用背景范围! (: (:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM