Swift Bluetooth Background Task every X minutes

Hi,

I'm developing an iOS app in Swift, and the app connects to wereable devices (Smart Bracelets).

With this wereables i've to write Data object to a BLE characteristic of the device every X minutes (example: 30 minutes).

What is the best approach to do this and to work in Background?

I think there is 2 ways:
  • Mantain the connection always active to the device, and write to the CBCharacteristic every 30 minutes

  • Close the connection every "write" and reconnect every 30 minutes and write to the CBCharacteristic.

By other hand the problem is not which way (I think the best is the second for battery saving), but my doubts are about how to do the Background processing of BLE writting (and reading).

Which would be the best way to do it to ensure that the task is executed? Do a BGTask? A scheduler?

In this task is no only have to work with BLE. It must write to CBCharasteristic, read from a CBCharasteristic, and send the information to an API Server (it's important to send the data in the moment of measurement, no after when the apps move to foreground), and in some ocassions show a Local Notification (depending of the measurement)

Thank you!
Answered by jmoratat in 630021022
Solved with BGProcessTask to do the characteristic write every X minutes!
Accepted Answer
Solved with BGProcessTask to do the characteristic write every X minutes!
Swift Bluetooth Background Task every X minutes
 
 
Q