1

Looking for a simple answer. I am going to build an application that needs accelerometer data from the user's Watch.

My question is: For the iPhone to retrieve accelerometer data from the user's Watch, do I need to build a Watch app also? I believe the answer is No, as I found another SO question/answer stating that you can read Heart Rate data every 5 minutes without a Watch App. Here's the link for reference:

Read Heart Rate in Apple Watch Series 3 without creating an app on the Watch

majors44
  • 113
  • 1
  • 8
  • i don't think it's possible and I don't think you can retrieve accelerometer data from Health Kit so you probably have to create a watch app. – Christoph Jun 08 '18 at 17:51

1 Answers1

3

To access the Apple Watch sensors, you will need an Apple Watch app
And due to limited background code execution capability on the Apple Watch, the user will have to explicitly interact with the app to start the sensors.

Basically, an iPhone app can access only it's own sensors. Same goes for an Apple Watch app.

There's no way right now in CMMotionManager to tap into another device's sensors.


The reason heart rate is available is because of HealthKit. That data is sent to the iPhone periodically.
You are basically communicating with HealthKit to get the latest heart rate, which... it recently got from the Apple Watch.

As for sensors, there's no central store that keeps the motion data of both devices.
Reasons probably being:

  • It doesn't make much sense to store this data
  • It's just too much data to sync!
  • Motion is something that is expected for extreme responsiveness so the sensor data from Apple Watch would have to be sent to the iPhone, in worst case, atleast every second. That would be a massive battery hog!

Now this part is a hypothetical solution but sorry, it's not possible.

Your next challenge would be to create a placeholder Apple Watch App Extension whose sole task will be to receive a message from the iPhone, via WatchConnectivity, to start it's sensors to get data, and send the samples back to the iPhone via WatchConnectivity again.

Sadly, Apple Watch Apps are really limited when it comes to executing code in the background so nope.

staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
  • to make sure I understand, there is no way to query the Apple Watch sensor data every 'x' amount of hours? I thought I saw somewhere that it is possible to read the last 12 hours worth of data? – majors44 Jun 08 '18 at 19:51
  • @user585493 [`CMMotionActivityManager()queryActivityStarting(from:to:to:withHandler)`](https://developer.apple.com/documentation/coremotion/cmmotionactivitymanager/1615929-queryactivitystarting) does give historical data upto 7 days. But I suspect it will still be device specific. Let me check this and get back to you. – staticVoidMan Jun 08 '18 at 20:42
  • @staticvoidmain - for my requirement, I would need the last 3 days worth of accelerometer data from the user's watch. that data would then by sent to the phone. Thank you so much, much appreciated. – majors44 Jun 08 '18 at 20:43
  • @user585493 It sure does seem device-specific but I'll need to get my hands on some test devices as I have alot of data here to figure. I can narrow it down and test newer values only but will check it out this coming week. In the mean time you could check this out: [using CMPedometer](https://medium.com/simform-engineering/count-steps-with-cmpedometer-on-iwatch-94b61bc3b87e) – staticVoidMan Jun 08 '18 at 21:28
  • @user585493 Alright, so I checked it out and it is as suspected: **the sensor history too is indeed device-specific**. My test: for a time-span of 5 minutes, I kept the iPhone stationary while I continues using the apple watch normally. Then when I checked the sensor logs for both devices, the watch logged a ton of data while the iPhone did not. – staticVoidMan Jun 12 '18 at 07:31
  • @staticvoidmain from additional reading, I am leaning towards this. On the Apple Watch, schedule a background refresh (midnight for example), that reads the last 24 hours worth of accelerometer data and send it to the server. – majors44 Jun 12 '18 at 12:18
  • @user585493 I don't think it's possible to schedule a background task on the Apple Watch OS 4 at a particular time. Infact, you can't do much on Apple Watch silently; the user must explicitly interact with your app. Anyways, I suggest you read [App Programming Guide for watchOS : Leveraging iOS Technologies](https://developer.apple.com/library/archive/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1) – staticVoidMan Jun 13 '18 at 07:16
  • @staticvoidmain - thanks for the link to the article. this is my last hurdle I am running into. From my reading/prototyping, there is no way to set the frequency of accelerometer data when retrieving history, correct? I know you can set the frequency if you want to read it real time. As you can imagine, if I query the accelerometer data for a couple of hours, that is a lot of data to process – majors44 Jun 14 '18 at 16:22
  • @user585493 Historical data is not as intricate as live data. `CMMotionActivityManager`'s historical data gives steps logged at their respective times so all the data is relevant imo. Btw, what kind of sensor information are you looking for? – staticVoidMan Jun 18 '18 at 09:06
  • We are retrieving the accelerometer X,Y, and Z values. – majors44 Jun 19 '18 at 11:39
  • @user585493 Hm... I am not 100% sure that `queryActivityStarting(from:to:to:withHandler:)` will provide you this data (_correct me if I am wrong_). You will need to use `startActivityUpdates(to:withHandler:)` but that comes with it's own complications in your case. – staticVoidMan Jun 19 '18 at 13:13