简体   繁体   English

iOS 应用程序在后台时蓝牙更新后发送网络请求

[英]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.

相关问题 在后台使用iOS应用进行网络请求 - Network request with iOS app in background 当应用程序处于后台时,核心蓝牙框架不会向iOS应用程序发送数据 - Core Bluetooth framework is not sending data to iOS app when the app is in background 当应用程序处于后台时,如何从ios 5应用程序向本地网络中的服务器发送一些请求? - How can i send some request from ios 5 app to server who is in local network, while app is in background? 通过蓝牙从iOS应用发送联系人 - Sending a contact from an iOS app via bluetooth 在App Store更新后,iOS应用程序是否继续在后台运行? - Does an iOS app continue to run in the background after an App Store update? iOS - 在后台应用时取消蓝牙连接 - iOS - Cancel bluetooth connection when app in background IOS App次要更新后,解析推送停止发送 - Parse Push Stops Sending after IOS App minor Update 在后台运行iOS蓝牙低功耗应用时,电池排放量是多少? - How large is the battery emissions while running an iOS Bluetooth Low Energy app in the background 从后台终止应用程序后,iOS更新位置 - iOS update location after kill app from Background iOS / Apple Watch:当应用程序处于后台时,不会触发iPhone应用程序网络请求回调块 - iOS / Apple Watch: iPhone app network request callback blocks not triggered when app is in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM