HealthKit: Workout saved on iPhone not showing in Activity app

Using HealthKit, I save

  • Training
  • Corresponding active energy samples
  • Matching Mileage / Mileage Spaces

I run the same code on an Apple watch and on an iPhone.

When I save to iPhone

  • I can choose a workout and samples in the iPhone app.
  • I see the workout and samples in the iPhone iPhone app.
  • Training and samples are not in the application for working with iPhone (bad)

When I save an apple on a watch

  • I can choose a workout and samples in the iPhone app.
  • I see the workout and samples in the iPhone iPhone app.
  • I see the training and samples in the application for working with the iPhone.

When I save an apple on the watch and delete it in my iPhone App

  • I canโ€™t choose the workout and samples in the iPhone app (good)
  • I do not see workouts and samples in the application for iPhone iPhone (good)
  • before watchOS 2.1 + iOS 9.2.1: I still see the workout and samples in the iPhone app (very bad)
  • verified using watchOS 2.2 beta 5 + iOS 9.3 beta 5: training and samples are deleted from the activity application on the iPhone (good)

When I save an apple on a watch and delete it in my Apple Watch app

  • tested on watchOS 2.2 beta 5 + iOS 9.3 beta 5: everything is as expected: not visible / selected on the watch and on the iPhone with any application mentioned (good with iOS 9.3)
  • before watchOS 2.1 + iOS 9.2.1: training and samples were not deleted on the iPhone. (bad until iOS 9.2.1)

Question

Am I doing something wrong or is HealthKit and the iPhone app working this way?

More specific question:

  • How to save workouts and samples on iPhone so that workouts and samples are not only visible in the Health app on one iPhone, but also in the Activity app on one iPhone?
  • How do I delete the exercises and samples on the iPhone that I saved using my Watch app, so 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 application can reliably save the workouts shown in the activity application. The iOS app can send data to the watch app, which is the easy part. But I do not know how to process this data on the clock in the background. The user must run the clock application to process the data.

The tests were conducted on hardware, not on the 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: the deletion is fixed, saving on the iPhone still does not work.

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

+5
source share
1 answer

This is definitely what is difficult to do at the moment! There are three separate questions with separate explanations.

  • When you save a workout on iPhone:

    • Workouts stored on the phone are not intended to provide activity credit. They should come from the Apple Watch.
    • Edit: from iOS 10, workouts stored on the phoneโ€™s account in the direction of Activity, if the user has an Apple Watch.
  • When you save a workout to the Apple Watch and delete it in the iPhone app :

    • In iOS 9.2 and earlier, deleting a pattern on the phone does not delete the same pattern in Apple Watch, where Activity is actually calculated. It is fixed in iOS 9.3.
    • Removing an HKWorkout sample HKWorkout not enough to remove the samples associated with this workout. For example, you must explicitly remove related active energy patterns if you no longer want them to exist. However, removing a workout should remove your contribution from activity rings. If this is not the case, then it sounds like an error, which will cost separately, since your original error is probably interpreted as a request for training from the iPhone account in Activity.
+3
source

Source: https://habr.com/ru/post/1243615/


All Articles