在iOS屏幕关闭时如何继续监视iBeacon? [英] How to continue monitoring iBeacon when screen is off in iOS?

查看:483
本文介绍了在iOS屏幕关闭时如何继续监视iBeacon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序以监视iBeacons.它在前景和背景方面均能很好地工作.即使屏幕关闭,我也需要它来继续监视.现在我的问题是,当我用肩膀按钮关闭屏幕时,NSLog显示iBeacon信号相应地熄灭(RSSI = 0,beacon.accuracy = -1.0),并且10秒钟后,根本没有找到任何信标. ,而连续调用委托方法locationManager:didRangeBeacons:inRegion:.屏幕关闭时,该应用程序似乎正在运行,但iOS关闭了iBeacon测距的位置服务.我试图设置"locationManager.pausesLocationUpdatesAutomatically = NO;"但仍然不起作用.关于这个问题有什么建议吗?预先感谢.

I am developing an iOS app to monitor iBeacons. It works well in both foreground and background. I also need it to keep monitoring even when the screen is off. Now my problem is, when I turn off the screen with the shoulder button, NSLog shows that the iBeacon signal goes off (RSSI=0, beacon.accuracy=-1.0) accordingly, and 10 seconds later, there is no beacon found at all, while the delegate method locationManager:didRangeBeacons:inRegion: is called continuously. It seems that the app is running when the screen is off but iOS turns off the location service for iBeacon ranging. I tried to set "locationManager.pausesLocationUpdatesAutomatically = NO;" but still doesn't work. Is there any advice on this issue? Thanks in advance.

推荐答案

似乎您是在进行测距而不是进行监视.仅当应用程序处于活动状态时(无论是在前台还是在后台),测距才有效.问题是,在您离开某个应用或锁定屏幕后,iOS会自动使该应用进入休眠状态.

It seems that you're doing ranging instead of monitoring. Ranging only works when the app is active—either in the foreground or in the background. The catch is, iOS will automatically put an app to sleep a few seconds after you navigate away from it, or lock the screen.

您要记住的是,iOS上确实没有永久背景状态"之类的东西.应用程序在过渡到暂停状态(例如允许它们完成上传/下载)时在后台运行一定的时间,并且有时还会有后台模式使应用程序在后台运行,但是这些模式通常是保留的适用于非常特定的应用程序-例如,音频"后台模式表示只要播放音乐等,应用程序就可以在后台运行.定位"服务有一个后台模式,但保留了以下功能:打开导航应用.

What you have to keep in mind is, there's really no such thing as "permanent background state" on iOS. Apps run in the background for some limited time while transitioning to the suspended state (to let them, e.g., finish uploads/downloads), and there are also Background Modes that sometimes enable an app to run in the background, but these are usually reserved for very specific apps—e.g., the "audio" Background Mode means an app can be running in the background as long as it plays music, etc. There is a Background Mode for "location" services, but it's reserved for turn-by-turn navigation apps.

信标监视,即使您的应用进入睡眠状态或由于内存不足而被iOS终止时,它仍会继续运行.当您进入或离开信标范围时,iOS会在后台启动您的应用程序以处理事件,并给事件几秒钟的时间(您可以使用

Beacon monitoring however continues running even if your app goes to sleep, or gets terminated by the iOS due to memory pressure. When you go in or out of range of a beacon, iOS will launch your app into the background to handle the event, giving it a few seconds (which you can extend up to a few minutes with a Background Execution Task) to do so (you can range during that time), but then it's back to sleep.

您可能还想看一下这个问题:
​​在应用程序处于后台时从信标接收信号

You might also want to take a look at this question:
Receive signal from beacon while app is in the background

这篇关于在iOS屏幕关闭时如何继续监视iBeacon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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