cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
548 stars 658 forks source link

Health 3.03 - Help getting larger chunks of the health data on iOS. #313

Closed SurgeryAI closed 2 years ago

SurgeryAI commented 3 years ago

Thank you for this plugin.

I would like to get larger chunks of health data from the iPhone into my app. The problem is that the app freezes for extending periods as it is accessing the phone health-kit. I am using async like the example uses. Unfortunately, "compute" does not work because it is accessing platform information.

I was curious if others have developed any solutions to get large chunks of data with this plugin without freezing the app.

mdichi commented 3 years ago

We are having this problem too. We are trying to read AH data over various periods (day, week, month). We can read data one day at a time. But if we try to read a bunch of days, the app seems to get blocked for a while (until the HealthKit query completes I assume). The UI of the app becomes non-responsive.

This is from HealthKit documentation: Queries return the current snapshot of the data in the HealthKit store. All queries run on an anonymous background queue. When the query is complete, it executes the results handler on the background queue. HealthKit provides different types of queries, each designed to return different types of data from the HealthKit store.

I haven't looked at the Health Plugin source (yet). But I wonder it is simply waiting for query results, which would block lengthy queries? Or does it have a results handler in place (which I don't think would cause blocking).

javiermelo1672 commented 3 years ago

It Is same for me, I have tried to get about 70000 field data, but the app doesn't finish the thread and the app get freezes and used about 270 mb of ram when is running. In my case I get Steps, Activity Burned and Walking Running distance. I apreciate to resolve this issue.

JNicoVM commented 3 years ago

Hello, Im facing the same issue, When a user has many files or data in a day the app just freezes, after few seconds it get normalize.

mdichi commented 3 years ago

Here is what we did and it seems to work. In our case we needed to extract up to 20 Apple Health variables for a period of time that could be any where from 3 months to 3 years.

We extract a small amount of data at a time. I think it was ten days at a time. This runs in a separate thread (ie. a future). We tried bigger amounts of data, but it would block and you couldn't switch apps or doing anything else within our app. This seems to work fine.

I think that the queries to Apple Health are slow to execute and that requesting a lot of data at once bogs it down.

You can also take a look at another app called QS Access. It is a quanified self app that extracts Apple Health data. You'll notice it extracts data for one variable at a time. It doesn't block.

NamanShergill commented 3 years ago

Is this still an issue with Flutter 2.5 which prioritizes UI over other things?

NamanShergill commented 3 years ago

So I've been researching. Seems like this can be fixed by requesting for the data from the HealthKit API in a different thread on the native side of the code.

Relevant discussion and directly related comment: https://github.com/flutter/flutter/issues/22024#issuecomment-659231894

matsunanaro commented 2 years ago

I've created PR #483 to offload time consuming tasks from the UI main thread on iOS. In addition, time consuming jobs will also be executed in so-called Isolates (lightweight threads) in Dart.

bardram commented 2 years ago

Fixed (addressed) as part of PR #483 and released as version 3.4.1.

Thanks to @matsunanaro for the PR.