Anu Arun
Anu Arun

Reputation: 35

Bluetooth low energy background

I am working on an iOS Bluetooth LE application. First I pair the IOS (central) to my bluetooth chip (peripheral)

1) Discover peripherals. 2) Connect to peripheral. 3) Getting services and characteristics. 4) Able to read data and write data from the characteristics. 5) Save the peripheral 6) Disconnect from the peripheral

When I run the app the second time, it connects to the peripheral automatically and writes and reads data from the characteristic and disconnects from it. The App works in the background for 10 minutes.

I would like to run this app in the background. That is I want to call the methods which connect, write and read values in the background every 6 hours. Is this possible? My App works in the background for only 10 minutes. Any suggestion will be of great help.

Upvotes: 0

Views: 1316

Answers (1)

benka
benka

Reputation: 4742

First you will need to be sure that you added:

<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-central</string>
    <string>bluetooth-peripheral</string>
</array>

to your Info.plist which will allow your app to run in the background.

However this will work as follows: it will allow your app to "wake up" to any bluetooth event and run methods that you like to fire when your app is getting any bluetooth activity.

So for example:

  • you can scan for bluetooth devices in the background and once found something that fits your criterias you can run code, as didDiscoverPeripheral fires (connect / read / write etc..).
  • you can be connected to a device and subscribed for notification from a specific characteristic. Once the characteristic changes value your app in the background should get a notification and didUpdateValueForCharacteristic callback will be called so again you can call methods from this point, still running in the background.
  • maybe you can think of other use-cases. I've mentioned these scenarios to give you an idea how you can definitely work in the background with BTLE.

These scenarios should not be limited to the 10 minutes timeframe.

However I have noticed that if you run something else in background mode (e.g: a loop) and the 10 minutes passes your app might be killed from the background so even the above mentioned callbacks will not work.

So to answer your 6 hours question: it would be possible if your BTLE device could initiate some BLE action every 6 hours to wake your app up. OTherwise I'm not sure you can start your activity from the app (ios) side.

Upvotes: 0

Related Questions