How to run watchOS app connected to BLE peripheral in the background?
Asked Answered
O

1

6

I'm creating a watchOS application. The app should connect to a BLE tag, which sends distance values to the apple watch. If the distance falls below a given value, the application should give some feedback to the user about this.

Reading about core bluetooth and background tasks, it doesn't seems like it's possible. If I'm correct, when the application is suspended, it will no longer receive data from the BLE peripheral. How should I approach this task? Is it possible to run an application like this for 8 hours in the background? I can't find any more information about this, and it seems like it's impossible.

Overcome answered 24/9, 2019 at 13:54 Comment(0)
P
5

There are restrictions to WatchOS apps using Bluetooth in the background, the main being:-

  • The minimum connection interval is 30ms instead of 15ms (for iOS devices).
  • The Apple watch can only operate as a central device.
  • The Apple watch can only be connected to two peripherals at one time.
  • The peripheral gets disconnected when the app goes into the background.

More details about this can be found in the following links:-

The only exception to this is if you use the HKWorkoutSession. More information about this can be found here.

I hope this helps.

enter image description here

Parochial answered 25/9, 2019 at 7:56 Comment(3)
Are these restrictions still in place for WatchOS 8?Anhwei
in WatchOS 8 I am not able to get notification or write to BLE device while in background during Workout session. this seems to be a changed behaviour compared to watchOS 7. The common suggestion is to use 'Bluetooth-central' In plist UIBackground-modes - but I am not able to upload an app to testFlight with this flag on, as it has some entitlement signing issue.Unimposing
There do seem to be issues (or at least more restrictions) in WatchOS 8 when it comes to background operation. I have seen this post where a user was able to recreate the problem using Apple's own demo application (developer.apple.com/forums/thread/692685) I am not aware if there's a proper solution for this.Parochial

© 2022 - 2024 — McMap. All rights reserved.