Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

How can I add exercise minutes manually in the Health app? #73

Open
erguncengiz opened this issue Feb 11, 2021 · 1 comment
Open

How can I add exercise minutes manually in the Health app? #73

erguncengiz opened this issue Feb 11, 2021 · 1 comment

Comments

@erguncengiz
Copy link

I paired my iPhone simulator with Apple Watch simulator. I want to read exercise minutes with this library but how can i do that?

@DinithHerath
Copy link

  • To get the exercise minutes from the health kit you need to modify the plugin.
  • It currently supports some of the health kit parameters such as step_count, distance_walk, etc.

Fortunately, I have modified the plugin to do that 😁

Use this in the pubspec.yaml as fitkit plugin.

fit_kit:
  git:
    url: git://github.com/dinithherath/FitKit.git

And in your code to get the exercise_minutes use this snippet.

if (!permissions) {
  log.d('RequestPermissions: Denied');
} else {
  try {
    final now = DateTime.now();
    FitDataStatistics resultAllSteps;
    FitDataStatistics resultAllExercise;
    try {
      resultAllSteps = await FitKit.readStatistics(
        DataType.STEP_COUNT,
        dateFrom: DateTime(now.year, now.month, now.day),
        dateTo: now,
      );
    } catch (e) {
      resultAllSteps = null;
    }
    try {
      resultAllExercise = await FitKit.readStatistics(
        DataType.EXERCISE_TIME,
        dateFrom: DateTime(now.year, now.month, now.day),
        dateTo: now,
      );
    } catch (e) {
      resultAllExercise = null;
    }
  } on UnsupportedException catch (e) {
    print(e.toString());
  }
}

This reads data from the health kit using the iOS cumulative sum method which will eliminate duplicates from your phone and apple watch.

If you get the work done please star my repo of Fitkit and follow me on github ❤
Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants