问题描述
我计划使用CoreBluetooth框架开发一个iOS应用程序,该框架可连续监视计步器外围设备并计算脚步数。
I am planning to develop an iOS application using CoreBluetooth framework which monitors a pedometer peripheral continuously and counts the footsteps.
我知道如果将背景执行模式设置为BLE Central,即使在后台应用程序也将继续接收BLE事件。
I know that if backgroud execution mode is set to BLE Central, the application will continue to receive BLE events even in the background.
Apple文档指出,如果由于内存不足而终止应用程序,系统可以保持如果采用了状态保存和恢复功能,则可以跟踪特定Central Manager的BLE事件。
Apple documentation states that in case the app gets terminated due to low memory, the system can keep track of BLE events for a particular Central Manager if state preservation and restoration is adopted.
假设我有一个在Central模式下运行的iOS应用程序。只要脚步特征发生变化,就订阅该应用程序以接收来自计步器的通知。
Assume I have an iOS application that operates in Central mode. The app is subscribed to receive notification from a Pedometer when ever the footstep characteristic changes.
我在我的应用程序中采用了以下内容。
I have adopted the following in my app.
- BLE中央背景模式
- BLE中央管理器的状态保存/恢复
我启动我的应用程序,扫描,配对并连接到计步器,该应用程序开始接收足迹。
I start my app, Scan, Pair and Connect to the pedometer and the app starts receiving footsteps.
我的问题:
-
现在,如果iPhone重新启动,我是否将继续接收BLE事件,以便我的应用程序将在后台启动,而用户不必再次手动启动该应用程序并连接到计步器吗?
Now if the iPhone reboots, Will I continue to receive BLE events so that my app will be launched in the background without the user having to manually launch the application again and connect to the pedometer?
如果该应用程序被用户使用多任务手势明确终止,该应用程序将能够接收BLE事件,而无需用户再次手动启动应用程序并连接到计步器?
If the app is terminated by the user explicitly using the multitasking gesture, Will the app be able to receive BLE events without the user having to manually launch the application again and connect to the pedometer?
是否可以在iO上启动我的应用程序要启动吗?
Is there a way to launch my application on iOS boot up?
推荐答案
- 现在,如果iPhone重新启动,我是否会继续接收BLE事件,以便我的应用程序将在后台启动,而用户不必再次手动启动该应用程序并连接到计步器?
您的应用将不会收到BLE事件,因为所有应用在重启后均以终止状态启动(尽管应用切换器)。用户必须在重新启动后至少手动启动您的应用一次才能使用BLE。
Your app won't receive BLE events because all apps are started in the terminated state after a reboot (despite remaining in the app switcher). The user will have to manually launch your app at least once after reboot in order for it to use BLE.
- 如果用户使用多任务手势明确终止了该应用程序,那么该应用程序将能够接收BLE事件,而无需用户再次手动启动该应用程序并连接到计步器吗?
与上述相同,该应用已进入终止状态,因此直到使用BLE才能进行通信
Same as above, the app has entered the terminated state, so it won't be able to communicate using BLE until it is explicitly launched again.
- 是否可以在iOS上启动我的应用程序
iOS无法提供任何在启动时启动应用程序的方式。
iOS doesn't provide any way to launch your application on boot.
iBeacons是我能找到的所有例外之一。如果您的应用程序注册为接收特定iBeacon的更新,则iOS将在找到该应用程序后启动您的应用程序(即使在重新启动后或用户从切换台明确杀死它的情况下)。当您收到iBeacon回调时,您可以启动所有BLE逻辑,然后它将照常在后台运行。当然,这意味着您需要在计步器上做为iBeacon广告,这可能可行,也可能不可行。
The one exception to all of this that I can find is iBeacons. If your app registers to receive updates for a specific iBeacon, iOS will launch your app when it finds it (even after a reboot or if the user explicitly kills it from the switcher). When you get the iBeacon callback you can start all your BLE logic and it will then run in the background per usual. Of course this means you need to advertise as an iBeacon on your pedometer, which may or may not be feasible.
请注意,iBeacon的检测非常挑剔,特别是重启后。您几乎无法保证iBeacon回调将以多快的速度启动您的应用程序。
Bear in mind the detection of the iBeacon is pretty finicky, especially after a reboot. You have little guarantee as to how fast or even if you will be delivered the iBeacon callback to start your app. But it's something.
这篇关于在iPhone重新启动时启动iOS BLE Central应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!