Skip to content

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

Description

@AdilHypeteq

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();
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions