gpt4 book ai didi

IOS 核心蓝牙 : App Running in Background When BLE is Disconnected

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:15:01 26 4
gpt4 key购买 nike

我试图在BLE断开连接时在后台运行我的应用程序。但是系统会在一段时间后杀死该应用程序。所以我阅读了苹果的文档--《Core Bluetooth Programming Guide》。最后我找到了以下内容在“iOS 应用程序的核心蓝牙后台处理”中的段落。

“Performing Long-Term Actions in the Background

Some apps may need to use the Core Bluetooth framework to perform long-term actions in the background. As an example, imagine you are developing a home security app for an iOS device that communicates with a door lock (equipped with Bluetooth low energy technology). The app and the lock interact to automatically lock the door when the user leaves home and unlock the door when the user returns—all while the app is in the background. When the user leaves home, the iOS device may eventually become out of range of the lock, causing the connection to the lock to be lost. At this point, the app can simply call the connectPeripheral:options: method of the CBCentralManager class, and because connection requests do not time out, the iOS device will reconnect when the user returns home. Now imagine that the user is away from home for a few days. If the app is terminated by the system while the user is away, the app will not be able to reconnect to the lock when the user returns home, and the user may not be able to unlock the door. For apps like these, it is critical to be able to continue using Core Bluetooth to perform long-term actions, such as monitoring active and pending connections.”

从这段话我们知道“监控事件和挂起的连接可以解决问题但是我找不到任何方法来实现监控事件和挂起的连接

Core Bluetooth Framework Reference

当 BLE 断开连接时,如何实现让我的应用程序在后台运行?

有人知道吗?

最佳答案

如果您使用 bluetooth-central Background Execution Mode 注册您的应用程序, 如果你的应用程序没有运行,它就会被启动,并且会得到它的委托(delegate)方法来处理发现和连接,比如 centralManager:didDiscoverPeripheral , 您可以从中调用 connectPeripheral:options: .

确实,系统可能会在后台终止您的应用程序,但它会为这些事件重新启动它。

系统不会重新启动您的应用程序以在后台执行 BLE 的唯一情况是用户在上一次启动时强行终止了该应用程序。系统会记住这一点,并且不会再次重新启动该应用程序,直到用户第一次手动重新启动它。

关于IOS 核心蓝牙 : App Running in Background When BLE is Disconnected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28813096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com