Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HealthKit: Workout saved on iPhone not visible in Activity App

Using HealthKit, I am saving

  1. A Workout
  2. Corresponding Active Energy Samples
  3. Corresponding Walk/Run distance samples

I'm running the same code on the apple watch and on the iPhone.

When I'm saving on the iPhone

  • I can select the workout and samples in my iPhone App
  • I can see the workout and samples in the iPhone Health App
  • The workout and samples are not in the iPhone activity app (bad)

When I'm saving on the apple watch

  • I can select the workout and samples in my iPhone App
  • I can see the workout and samples in the iPhone Health App
  • I can see the workout and samples in the iPhone activity app

When I'm saving on the apple watch and delete it in my iPhone App

  • I can not select the workout and samples in my iPhone App (good)
  • I can not see the workout and samples in the iPhone Health App (good)
  • up until watchOS 2.1 + iOS 9.2.1: I still can see the workout and samples in the iPhone activity app (very bad)
  • tested with watchOS 2.2 beta 5 + iOS 9.3 beta 5: workout and samples are removed from the activity app on the iPhone (good)

When I'm saving on the apple watch and delete it in my Apple Watch App

  • tested with watchOS 2.2 beta 5 + iOS 9.3 beta 5: Everything is as expected: not visible/selectable on the watch and on the iPhone with any mentioned app (good since iOS 9.3)
  • up until watchOS 2.1 + iOS 9.2.1: Workout and samples were not deleted on the iPhone. (bad until iOS 9.2.1)

Question

Am I doing something wrong or is this the way HealthKit and the iPhone Activity App works?

More specific question:

  • How can I save workouts and samples on the iPhone, such that the workouts and samples are not only visible in the Health App on the same iPhone, but also in the Activity App on the same iPhone?
  • How can I delete workouts and samples on the iPhone, that I saved using my Watch App, such that the workouts and samples are not only deleted in the Health App on the same iPhone, but also deleted in the Activity App on the same iPhone?

If this is not my mistake, no iOS app could reliably save workouts that are shown in the activity app. The iOS app could send the data to the watch app, that is the easy part. But I know no way to process this data on the watch in background. The user has to start the watch app to process the data.

The tests were made on hardware, not on a simulator. iOS 9.2.1, watchOS 2.1

I added tests using watchOS 2.2 beta 5 + iOS 9.3 beta 5. I edited the results above. Summary: deleting is fixed, Saving on the iPhone still doesn't work.

With iOS 9.3 / watchOS 2.2, Apple added HKActivitySummary, HKActivitySummaryQuery and HKActivityRingView. In short: everything said about the activity app on the iPhone also applies to HKActivitySummaryQuery. They share features and bugs described above.

like image 374
Gerd Castan Avatar asked Feb 22 '16 21:02

Gerd Castan


1 Answers

This is definitely something that is tricky to navigate at the moment! There are three distinct issues with separate explanations.

  1. When you save a workout on the iPhone:

    • Workouts saved on the phone are not intended to provide Activity credit. They must originate on Apple Watch.
    • Edit: as of iOS 10, workouts saved on the phone count towards Activity if the user has an Apple Watch.
  2. When you save the workout on Apple Watch and delete it in the iPhone App:

    • In iOS 9.2 and earlier, deleting a sample on the phone does not delete the same sample on Apple Watch, where Activity is actually calculated. This is fixed in iOS 9.3.
    • Deleting an HKWorkout sample is not sufficient to delete the samples that you associated with that workout. For example, you need to delete the associated active energy samples explicitly if you don't want them to exist anymore. That said, deleting the workout should remove its contribution from the Activity rings. If it doesn't, then that sounds like a bug that would be worth filing separately since your original bug was probably interpreted as a request to have workouts from iPhone count in Activity.
like image 189
Allan Avatar answered Oct 01 '22 19:10

Allan