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

查看:117
本文介绍了应用程序未运行时的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.

测试时要小心这是因为有时在iOS识别区域状态转换之前打开/关闭iBeacon需要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.

编辑:从iOS 8开始,您需要确保已经调用并成功获得 locationManager.requestAlwaysAuthorization() as locationManager.requestWhenInUseAuthorization()只允许在前台检测到信标。

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.

我发布了一个详细讨论这一切是如何工作的这篇博文。

I have posted a detailed discussion on how this all works in this blog post.

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

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