简体   繁体   English

背景iOS中的信标监控

[英]Beacon monitoring in background iOS

I am developing an iOS app in Swift that monitors for beacon events. 我正在Swift中开发一个监控信标事件的iOS应用程序。 This is my first real beacon endeavor. 这是我第一次真正的灯塔努力。

I am using Estimote beacons, but am not using the Estimote SDK. 我正在使用Estimote信标,但我没有使用Estimote SDK。 I am using core location and a CLLocationManager with didExit and didEnter events. 我正在使用核心位置和带有didExit和didEnter事件的CLLocationManager。

I am only listening for beacons that are registered with the current user that is signed in to my app. 我只是在监听已注册到我的应用程序的当前用户注册的信标。 For example, John Doe could be registered with beacons A and B, while Mary Sue is only registered to beacon C. I am experiencing a lot of false leaves, and wonder if it is because of where I am implementing my code. 例如,John Doe可以在信标A和B中注册,而Mary Sue只注册到信标C.我遇到了很多假叶子,并且想知道是不是因为我在实现我的代码。

I understand that there is a default 30 second latency when validating a leave event, but I am experiencing periods of longer than 30 seconds without a bluetooth signal from point blank range. 我知道在验证离开事件时有一个默认的30秒延迟,但是我遇到的时间超过30秒而没有来自点空白范围的蓝牙信号。 Perhaps implement a 30 minute window rather than 30 seconds for a leave validation? 也许实施一个30分钟的窗口而不是30秒的休假验证?

Since a user has to sign-in in order to know what beacons to monitor, the location manager resides within the user's default profile view controller. 由于用户必须登录才能知道要监视的信标,因此位置管理器位于用户的默认配置文件视图控制器中。 I successfully get beacon interaction even when the phone is locked, but it is not consistent. 即使手机被锁定,我也成功获得了信标交互,但这并不一致。 I am concerned because I know that the view controller itself is suspended/activated at the iPhone's discretion and may be revealing flaws in my logic. 我很担心,因为我知道视图控制器本身是由iPhone自行决定暂停/激活的,并且可能揭示了我逻辑中的缺陷。

Should all location oriented code be placed within the app delegate file? 是否应将所有面向位置的代码放在app委托文件中? If I implement a protocol from my profile view to the app delegate, I can instantiate it there within the app delegate first and then retrieve the beacon data later, once the user is signed in. 如果我将我的配置文件视图中的协议实现到应用程序委托,我可以先在应用程序委托中实例化它,然后在用户登录后再检索信标数据。

I have struggled to find an "iOS beacon convention" in my research, just examples that provide some results. 我一直在努力在我的研究中找到一个“iOS beacon convention”,只是提供一些结果的例子。 Not too sure whats actually considered proper practice. 不太确定什么是实际上认为适当的做法。

Thanks! 谢谢!

It is common to use a software filter to ignore spurious region exit events if an entry event happens soon afterward. 如果入口事件很快发生,则通常使用软件过滤器来忽略虚假区域退出事件。

To make this independent of any one ViewController, it is important to have the logic triggered by the AppDelegate. 为了使其独立于任何一个ViewController,重要的是让AppDelegate触发逻辑。 Two choices here: 这里有两个选择:

  • Put region monitoring callbacks and filter logic directly in the AppDelegate. 将区域监视回调和过滤逻辑直接放在AppDelegate中。 This is appropriate for small and simple apps. 这适用于小型和简单的应用程序。

  • Put callbacks and filter logic in a custom class, and initialize it from the AppDelegate's didFinishLaunching method. 将回调和过滤逻辑放在自定义类中,并从AppDelegate的didFinishLaunching方法初始化它。 This is the best approach for larger and more complex apps to keep the AppDelegate simple and clean. 对于更大,更复杂的应用程序来说,这是保持AppDelegate简单和干净的最佳方法。

Either way, it is critical to trigger starting of monitoring from the didFinishLaunching method. 无论哪种方式, 从didFinishLaunching方法触发监控的开始至关重要。 This ensures proper background CoreLocation setup should your app be auto launched by region transitions. 如果应用程序通过区域转换自动启动,这可确保正确的背景CoreLocation设置。

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

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