[英]Sending network request after bluetooth update while iOS app is in background
I have an app that is keeping an active connection to a BLE device.我有一个与 BLE 设备保持活动连接的应用程序。 The BLE device is sending data from time to time to the app, and I want the app to send this data to a server.
BLE 设备不时向应用程序发送数据,我希望应用程序将此数据发送到服务器。
Note the app can be in foreground, background, the iPhone locked, or any possible state.请注意,应用程序可以在前台、后台、iPhone 锁定或任何可能的 state 中。
What I see is that if the app is in the background (after a while), when iOS awakes the app upon a new BLE update from my hardware device, the network request fails instantaneously (like it's not granting network access).我看到的是,如果应用程序在后台(一段时间后),当 iOS 从我的硬件设备进行新的 BLE 更新时唤醒应用程序时,网络请求会立即失败(就像它没有授予网络访问权限一样)。
Does anybody know how to approach this issue?有人知道如何解决这个问题吗? note that
UIBackgroundTask
doesn't seem to work as they can only be requested from the foreground (right?), and in my case, the app is already in the background when the BLE update hits the phone.请注意,
UIBackgroundTask
似乎不起作用,因为它们只能从前台请求(对吗?),在我的情况下,当 BLE 更新到达手机时,应用程序已经在后台。
Any ideas?有任何想法吗?
The approach I finally took is to use a background configured URLSession connection.我最终采用的方法是使用后台配置的 URLSession 连接。 Instead of making the app responsible to upload the data, with URLSession with a background mode, it will request OS to upload the data and notify the app once done.
不是让应用程序负责上传数据,而是使用具有后台模式的 URLSession,它会请求操作系统上传数据并在完成后通知应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.