Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected behavior of BT in background #54

Open
dennislysenko opened this issue Apr 1, 2024 · 2 comments
Open

Expected behavior of BT in background #54

dennislysenko opened this issue Apr 1, 2024 · 2 comments

Comments

@dennislysenko
Copy link

Hi @mickeyl, first off, thanks for helping to troubleshoot the other issue I had recently.

I was curious what the expected behavior is of BT when going into the background. I have this app using LTSupportAutomotive, that runs a web server in the background using the silent audio trick exposing OBD readings that are polled every 0.3s (we're just running it via Testflight, it doesn't need to pass app review).

Project: https://github.com/dennislysenko/OBD2Loxone

image

We have all these background modes selected. However when going to background, the web server keeps running for hours (indicating that the app is still awake, as intended), but the BT connection seems to go down.

Do you know what the expected behavior is of BLE under these conditions, when the app is running in the background (not getting killed)? I did a quick search for any UIApplicationDidEnterBackground etc. in the LTSupportAutomotive repo, and didn't find any reason to think the library would switch off BT connections when backgrounding.

@mickeyl
Copy link
Owner

mickeyl commented Apr 5, 2024

This is a very interesting question. I still don't have the final verdict and need to carry out more tests, but it seems there are a whole lot of factors involved:

  • Operating system version and device grade (pro or not).
  • Whether you are a TestFlight/AppStore app or not.
  • Whether the Xcode debugger is connected to the device.
  • Whether power saving mode is enabled.
  • Whether actual BLE traffic is happening or not.
  • Whether you have an Apple Watch (or auxiliary BLE devices, such as pacemakers, fitness equipment, etc.) connected.
  • What kind of operations are carried out in the foreground app.

In one of my production apps, I'm using BLE via L2CAP COC. This app has only [x] Uses Bluetooth LE accessories enabled and survives 27 seconds in background, before the app is killed. The L2CAP connection holds for so long, but (naturally) gets closed when the app is killed.

Let me do the silent audio trick next week and check whether I can get the L2CAP connection to hold any longer.
I'm also not sure whether L2CAP COC has any other runtime characteristics than the standard BLE connectivity.

Like I said, this is a complex, but very interesting topic and authoritative or definite information are little. Perhaps we can work together here, sharing our experiences.

@mlawlerau
Copy link

I have had my app run for much longer than 30s in background, but I dont think it has lasted longer than 30m. I will need mine to run for hours in the background. I am interested in this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants