Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 362
adamb Avatar asked Sep 24 '19 13:09

adamb


People also ask

Does Apple Watch support BLE?

Pairing Apple Watch with iPhone is secured using an out-of-band process to exchange public keys, followed by the Bluetooth Low Energy (BLE) link shared secret. Apple Watch displays an animated pattern, which is captured by the camera on iPhone.

How do you turn on background on Apple Watch?

To do so, first, head to the 'Watch' app either from the home screen or from the App Library of your iPhone. Next, locate and tap on the 'General' option to proceed. After that, on the 'General' settings page, tap on the 'Background App Refresh' option to proceed.

How do you deploy the watchOS app?

Just build and run your iPhone application. Then, in the "Apple Watch" app on your iPhone, find your application, tap on it, and activate "Show App on Apple Watch". It may take a few seconds until the your Watch app has been installed.


1 Answers

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:-

  • https://www.raywenderlich.com/336-core-bluetooth-in-watchos-tutorial
  • https://developer.apple.com/videos/play/wwdc2017/712/

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

like image 147
Youssif Saeed Avatar answered Sep 22 '22 16:09

Youssif Saeed