且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iOS屏幕关闭时如何继续监视iBeacon?

更新时间:2023-11-03 16:02:34

似乎您是在进行测距而不是进行监视.仅当应用程序处于活动状态时(无论是在前台还是在后台),测距才有效.问题是,在您离开某个应用或锁定屏幕后,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