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

No new data on subsequent queries #43

Open
Parfyonator opened this issue May 15, 2022 · 4 comments
Open

No new data on subsequent queries #43

Parfyonator opened this issue May 15, 2022 · 4 comments

Comments

@Parfyonator
Copy link

Describe the bug
The fresh and up-to-date data is returned only on the very first query. The subsequent queries return the subset of the very first query: as the time window moves forward the less and less data is left in the returned list.

To Reproduce
Steps to reproduce the behavior:

final prefUnits = await HealthKitReporter.preferredUnits([QuantityType.heartRate]);
final hrUnits = prefUnits.first.unit;

// make multiple calls with some time intervals to reproduce
final now = DateTime.now();
final hbQuery = await HealthKitReporter.quantityQuery(QuantityType.heartRate, hrUnits, Predicate(now.subtract(Duration(seconds: 120)), now));
print(hbQuery.map((e) => e.harmonized.value));

Eventually the list becomes empty.

Expected behavior
Get up-to-date data on every query (as it happens on the very first query).

Desktop (please complete the following information):

  • OS: iOS

Smartphone (please complete the following information):

  • Device: iPhone11
  • OS: iOS15.4.1
@Parfyonator
Copy link
Author

Here is an example app that shows the problem:
https://github.com/Parfyonator/HealthKitReporterTest

The are two ways to get new portion of data:

  • collapse the running application and bring it back again
  • wait several minutes (time interval is not consistent and varies) and get new portion of data

Additional note: I'm using Apple Watch 7 as a heart beat sensor.

@Parfyonator
Copy link
Author

Forgot to mention: in order to get data one have to launch workout session. It should be done manually, since the startWatchApp method doesn't seem to work. The following code

final isStartedWatchApp = await HealthKitReporter.startWatchApp(
  WorkoutConfiguration(
    WorkoutActivityType.coreTraining.value,
    2,
    0,
    const WorkoutConfigurationHarmonized(0, 'm'),
  )
);

throws exception

PlatformException (PlatformException(StartWatchApp, Error in startWatchApp, Optional(Error Domain=com.apple.healthkit Code=550 "Unable to launch watch app" UserInfo={NSLocalizedDescription=Unable to launch watch app}), null))

@kvs-coder
Copy link
Owner

kvs-coder commented Jun 9, 2022

Hi @Parfyonator

Thank you for the raising the issue.
I tried to reproduce your steps and used the code you attached in the first message. If I understood you correctly, your point was, that if one calls a query in a repeated manner during some amount of time every new payload has less amount of entries than the previous?

So I wrapped your code in a simple loop, and created and called a query 10 times. It shows me always the same output as I expected (I just took the time interval be longer, because it is obvious that you can get less data, if your time interval is only two minutes and every time you recreate a now date)

Bildschirmfoto 2022-06-09 um 11 12 43

Regarding the startWatchUp will investigate more

@Parfyonator
Copy link
Author

Hi @VictorKachalov

Thank you for your feedback. I guess you've misunderstood me: now = DateTime.now() should be in the for loop so that the new data (for the last 2 minutes) is being retrieved every time. I'm sorry for placing final keyword before now. It must have been very confusing.

Please refer to my simple example app provided in the second comment. I implemented there the logic I hope to see working. Basically I want to get heart rate data in real-time (every second or few).

I'm not sure if this task with real-time heart rate readings may be accomplished without a companion app on Apple Watch, so I ended up writing one in Swift that streams heartbeat data from apple watch to my flutter app.

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

2 participants