2

I am simply developing a pedometer app with flutter backed by firebase. pedometer package is used for detecting steps but we need to update current steps to 0 at midnight.

Using workmanager and background_fetch approaches can be used for every 15 minutes tasks but they are not robust in ios and it can not be scheduled for specific time, as i know. How can i execute a code at midnight?

Muhtar
  • 1,506
  • 1
  • 8
  • 33
  • You can't and don't need to. Use the `timeStamp` of the `event` to work out which day the steps are for – Paulw11 Sep 30 '22 at 23:52
  • Could you give me an example? I could not figure out what you said. We have timestamp of event but when the app is not workin we dont know the stepcounts from when – Muhtar Oct 01 '22 at 08:56
  • Yes, looking at the source code of that plug-in, it uses a very simplistic approach to getting data from CMPedometer. I assumed that it used the `timeStamp` to give you the step count for relevant periods but it doesn't do that. You can query CMPedometer to get steps for a specific time range, up to 7 days in the past. The approach on iOS would be to query CMPedometer when your app returns to the foreground to get the number of steps for yesterday (and any other days in the past for which you don't have final data) – Paulw11 Oct 01 '22 at 11:08
  • You could also write or find a better plug-in for iOS that correctly passes through the date from the [`CMPedometerData`](https://developer.apple.com/documentation/coremotion/cmpedometerdata) so that you can record the steps that occurred while your app was suspended against the correct date. – Paulw11 Oct 01 '22 at 11:13

0 Answers0