简体   繁体   English

在后台从BLE读取数据

[英]Read data from BLE in background

I have a problem with reading data from BLE device in background. 我在后台从BLE设备读取数据时遇到问题。 Every 30 seconds I must ask my device for data and save it in database. 每隔30秒,我必须向我的设备询问数据并将其保存在数据库中。 Unfortunately Timer is not working in background so I tried to use CLLocationManager and update location every 30 second and then read value from device. 不幸的是,Timer在后台无法运行,因此我尝试使用CLLocationManager并每30秒更新一次位置,然后从设备读取值。 It is working pretty well but not always. 它运行良好,但并非总是如此。 When I leave app in the foreground and wait until it will enter background automatically after certain period of time, location manager doesn't work and I don't know why. 当我将应用程序置于前台并等待一段时间后它将自动进入后台时,位置管理器将无法工作,我也不知道为什么。

Is there any solution to read data every 30 seconds from device when app is in the background? 有什么解决方案可以在后台运行应用程序时每30秒从设备读取一次数据?

If possible, you can let the peripheral notify the central every 30 seconds. 如果可能,您可以让外围设备每30秒通知一次中心。 Then if you have implemented State preservation and restoration correctly, iOS should wake up your app so you can handle the notifications. 然后,如果您正确实施了状态保存和还原,iOS应唤醒您的应用程序,以便您处理通知。

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

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