Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In iOS take too much time to return steps data. #114

Open
AdilHypeteq opened this issue May 25, 2023 · 0 comments
Open

In iOS take too much time to return steps data. #114

AdilHypeteq opened this issue May 25, 2023 · 0 comments

Comments

@AdilHypeteq
Copy link

I have implemented code as below, but it's taken time to return steps data in iOS.

const weeks = 4;
    const interval = 'hour';
    const tonigth = new Date();
    // Set date to midnight tonight:
    tonigth.setHours(0, 0, 0, 0);
    tonigth.setDate(tonigth.getDate() + 1);

    const weekAgo = new Date(
      tonigth.getTime() - weeks * 7 * 24 * 60 * 60 * 1000,
    );

    const startDate = Start ? Start : weekAgo.toString();
    const endDate = End ? End : tonigth.toString();

const fetchSteps = async () => {
      const steps = await Fitness.getSteps({startDate, endDate, interval});
      console.log('steps :', steps);
      return steps.map(step => {
        return {
          ...step,
          startDate: moment(step.startDate).toDate(),
          endDate: moment(step.endDate).toDate(),
        };
      });
    };
    const permissions = [
      {
        kind: Fitness.PermissionKinds.Steps,
        access: Fitness.PermissionAccesses.Read,
      },
    ];
    const authorized = await Fitness.isAuthorized(permissions);
    if (authorized) {
      if (Platform.OS === 'android') {
        return fetchSteps();
      } else {
        return fetchSteps();
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant