简体   繁体   English

在iPhone重启时启动iOS BLE Central应用程序

[英]Launching iOS BLE Central application on iPhone reboot

I am planning to develop an iOS application using CoreBluetooth framework which monitors a pedometer peripheral continuously and counts the footsteps. 我计划使用CoreBluetooth框架开发iOS应用程序,该框架持续监视计步器外围设备并计算足迹。

I know that if backgroud execution mode is set to BLE Central, the application will continue to receive BLE events even in the background. 我知道如果将backgroud执行模式设置为BLE Central,则即使在后台,应用程序也将继续接收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. Apple文档指出,如果应用程序因内存不足而终止,系统可以在采用状态保留和恢复时跟踪特定中央管理器的BLE事件。

Assume I have an iOS application that operates in Central mode. 假设我有一个以中央模式运行的iOS应用程序。 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 Central background mode BLE中央背景模式
  • BLE State preservation/restoration for Central Manager BLE国家保护/恢复中央经理

I start my app, Scan, Pair and Connect to the pedometer and the app starts receiving footsteps. 我启动我的应用程序,扫描,配对并连接到计步器,应用程序开始接收足迹。

My Questions: 我的问题:

  1. 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? 现在,如果iPhone重新启动,我是否会继续接收BLE事件,以便我的应用程序将在后台启动,而无需用户再次手动启动应用程序并连接到计步器?

  2. 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? 如果用户明确使用多任务手势终止应用程序,应用程序是否能够接收BLE事件而无需用户再次手动启动应用程序并连接到计步器?

  3. Is there a way to launch my application on iOS boot up? 有没有办法在iOS启动时启动我的应用程序?

  1. 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? 现在,如果iPhone重新启动,我是否会继续接收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). 您的应用将不会收到BLE事件,因为所有应用都会在重新启动后以终止状态启动(尽管仍保留在应用切换器中)。 The user will have to manually launch your app at least once after reboot in order for it to use BLE. 用户必须在重启后至少手动启动一次应用程序才能使用BLE。

  1. 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? 如果用户明确使用多任务手势终止应用程序,应用程序是否能够接收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. 与上面相同,应用程序已进入已终止状态,因此在再次明确启动之前,它将无法使用BLE进行通信。

  1. Is there a way to launch my application on iOS boot up? 有没有办法在iOS启动时启动我的应用程序?

iOS doesn't provide any way to launch your application on boot. iOS无法提供任何启动应用程序的方法。

The one exception to all of this that I can find is iBeacons. 我能找到的所有这一个例外是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). 如果您的应用程序注册接收特定iBeacon的更新,iOS将在找到它时启动您的应用程序(即使重启后或用户明确将其从切换台中杀死)。 When you get the iBeacon callback you can start all your BLE logic and it will then run in the background per usual. 获得iBeacon回调后,您可以启动所有BLE逻辑,然后按常规在后台运行。 Of course this means you need to advertise as an iBeacon on your pedometer, which may or may not be feasible. 当然这意味着你需要在你的计步器上做广告作为iBeacon,这可能是也可能是不可行的。

Bear in mind the detection of the iBeacon is pretty finicky, especially after a reboot. 请记住,iBeacon的检测非常挑剔,尤其是重启后。 You have little guarantee as to how fast or even if you will be delivered the iBeacon callback to start your app. 您无法保证多快,甚至是否会通过iBeacon回调来启动您的应用。 But it's something. 但这是件好事。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM