应用程序未运行时的 iBeacon 通知 [英] iBeacon Notification when the app is not running

查看:24
本文介绍了应用程序未运行时的 iBeacon 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法制作了一个 iBeacon,当信标在范围内时,它会在我的 iPhone 上触发本地推送通知.当应用程序处于后台模式时,它完美地工作.

I managed to make an iBeacon which triggers a local push notification on my iPhone when the beacon is in range. It's perfectly working when the app is in background mode.

我的问题是:即使应用程序没有运行,甚至在后台也没有,我是否可以触发通知?

My question is: Can I trigger the notification even when the app is not running, not even in the background?

我认为这是可能的,但我不确定.如果是这样,我该如何实现?

I thought this was possible but I'm not sure. If so, how can I accomplish this?

谢谢!

推荐答案

是的,这是可能的,而且应该是自动的.

Yes, it's possible and should be automatic.

在您创建 CLBeaconRegion 并开始对其进行监控后,位置服务将跟踪您的手机是在该区域内还是在该区域外,即使您的应用未运行也是如此.如果您的应用程序在转换期间没有运行,iOS 会将您的应用程序启动到后台几秒钟以调用适当的 CLLocationManagerDelegate 方法.

After you have created a CLBeaconRegion and started monitoring on it, Location Services will keep track of whether your phone is in or out of the region, even when your app isn't running. If you app isn't running during a transition, iOS will launch your app into the background for a few seconds to call the appropriate CLLocationManagerDelegate methods.

我通过我自己的应用程序的实验发现了上述行为,但也通过 Apple 的 AirLocate 示例程序见证了它.使用 AirLocate,如果您设置了监控区域然后重启手机,AirLocate 仍会在手机进入该区域后立即发送本地通知.

I found out the above behavior through experimentation with my own app, but have also witnessed it with Apple's AirLocate sample program. With AirLocate, if you set up a monitoring region then reboot your phone, AirLocate will still deliver a local notification as soon as the phone enters the region.

测试时要小心,因为有时在打开/关闭 iBeacon 后 iOS 识别区域状态转换之前需要长达 4 分钟的时间.编辑:从 iPhone 5 开始,应用程序通常会使用硬件加速在几秒钟内检测到信标,如果硬件加速不可用,则最多可能需要 15 分钟.

Take care when testing this, because sometimes it takes up to 4 minutes after turning on/off an iBeacon before iOS recognizes the region state transition. EDIT: As of the iPhone 5, apps will typically use hardware acceleration to detect beacons within a few seconds, and if hardware acceleration is not available, it can take up to 15 minutes.

编辑 3: 作为 iOS 13,您必须确保用户实际授予后台权限,而不是仅一次"或使用时"权限,这些权限在操作系统中被大量推送他们呈现给用户的对话框.请参阅此处了解详情.

EDIT 3: AS of iOS 13, you must make sure the user actually grants background permission and not "only once" or "when in use" permission which are heavily pushed by the operating system in the dialogs they present to the user. See here for details.

EDIT 2: 从 iOS 8 开始,您需要确保已调用并成功获取 locationManager.requestAlwaysAuthorization() 作为 locationManager.requestWhenInUseAuthorization() 只允许在前台检测到信标.

EDIT 2: As of iOS 8, you need to make sure you have called and successfully obtained locationManager.requestAlwaysAuthorization() as locationManager.requestWhenInUseAuthorization() only lets beacons be detected in the foreground.

我在 这篇博文.

这篇关于应用程序未运行时的 iBeacon 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆