iBeacons:如果app在后台,则只有在显示锁定屏幕时才会调用locationManager:didEnterRegion: [英] iBeacons: If app is in background, locationManager: didEnterRegion: is called only when lock screen displayed

查看:110
本文介绍了iBeacons:如果app在后台,则只有在显示锁定屏幕时才会调用locationManager:didEnterRegion:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款监控iBeacon地区的iOS应用。当应用程序在后台运行时,我希望它在遇到特定的iBeacon区域时发送本地通知。一切正常,除了一件事:locationManager:didEnterRegion显然不会被调用,直到用户显示锁定屏幕。因此,即使设备在应用程序处于后台时通过iBeacon区域,他们也不会在显示锁定屏幕之前收到通知。

I'm working on an iOS app that monitors for iBeacon regions. When the app is running in the background, I want it to send a local notification whenever it encounters a particular iBeacon region. Everything works fine, except for one thing: locationManager: didEnterRegion evidently doesn't get called until the user displays the lock screen. So even if the device passed through an iBeacon region while the app was in the background, they don't get the notification until they display the lock screen.

我已经还尝试使用startMonitoringForRegion,这种工作 - 如果应用程序在后台运行,则locationManager:didDetermineState:当设备进入iBeacon区域时触发。但是,它只执行一次 - 如果用户随后退出并重新进入iBeacon区域,则locationManager:didDetermineState不会再次触发。

I've also tried using startMonitoringForRegion, and that sort of works -- if the app is running in the background, locationManager: didDetermineState: fires when the device enters the iBeacon region. However, it only does so once -- if the user subsequently exits and reenters the iBeacon region, locationManager: didDetermineState does not fire again.

我正在运行iPhone 5s并且使用iPhone 4s作为iBeacon,如果这有任何区别。

I'm running an iPhone 5s and using an iPhone 4s as the iBeacon, if that makes any difference.

更正:这种现象显然只发生在我使用iPhone时4s作为客户。如果我使用5s,通知会立即发送。

Correction: This phenomenon is evidently only happening when I use an iPhone 4s as the client. If I use a 5s, the notification is delivered immediately.

推荐答案

只是想获取更多信息。您是否在CLBeaconRegion上将notifyEntryStateOnDisplay设置为YES?它听起来像。

Just trying to get more info. Have you set notifyEntryStateOnDisplay to YES on the CLBeaconRegion? It sounds like it.

来自文档:


当设置为YES时,当用户打开显示器并且设备已经在该区域内时,位置管理器发送信标通知。即使您的应用未运行,也会发送这些通知。在这种情况下,系统会将您的应用程序启动到后台,以便它可以处理通知。在这两种情况下,位置管理器都会调用locationManager:didDetermineState:forRegion:其委托对象的方法。

When set to YES, the location manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation, the system launches your app into the background so that it can handle the notifications. In both situations, the location manager calls the locationManager:didDetermineState:forRegion: method of its delegate object.

此属性的默认值为NO。

The default value for this property is NO.

这篇关于iBeacons:如果app在后台,则只有在显示锁定屏幕时才会调用locationManager:didEnterRegion:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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