kvs-coder / health_kit_reporter

A Flutter wrapper for the HealthKitReporter library
https://pub.dev/packages/health_kit_reporter
MIT License
38 stars 38 forks source link

Does ObserverQuery work when app is killed? #3

Open spiritinlife opened 3 years ago

spiritinlife commented 3 years ago

It is not clear by the documentation, if observerQuery works when app is killed. My current understanding is that it doesn't work. If that is true, do you think you will support it in the future?

kvs-coder commented 3 years ago

Hi @spiritinlife

According to the Apple Documentation related to background updates, the observing queries should be initilized in didFinishLaunchingWithOptions of AppDelegate file. This background delivery and observing queries combination will allow you to get notifications from Apple Health even if your app is killed. The idea is that whenever a new value appears/disappears in Apple Health, the observerQuery's update handler will be triggered, and the code you provide there will be executed. But, unfortunately this works only natively.

I am afraid there is no chance for now to do the same in Flutter part of the library, i.e put observation in "main" function. Because events handling between the native part and the flutter part starts when the subscription is set on the flutter side.

Although the observer query will be still running when the app has "Not Running" lifecycle state, the stream subscription on the flutter side will be canceled when the app will be killed by the system.

I will try to adjust the explanation in README

kvs-coder commented 3 years ago

Btw, in order to see how ObserverQuery is actually working, you can check out a native example of the HealthKitReporter. It is the base library for this flutter wrapper

kvs-coder commented 3 years ago

I will also present some changes in event handling in new version

spiritinlife commented 3 years ago

@VictorKachalov thx for the quick response.

This library seems to be able to do it https://github.com/nanoglobal/nano_healthkit. Also https://github.com/fluttercommunity/flutter_workmanager should be doing something similar.

kvs-coder commented 3 years ago

Ok, it appeared, that it was suppose to work all the time :) but was a lack of an appropriate Capability for background fetch and an argument exceptions in enabling background deliveries. You may try again. In the example app I added some local notifications, which should be triggered if some data changes. The version is 1.0.5 now.

kvs-coder commented 3 years ago

hi @spiritinlife

Have you already tried to use this package with observing queries on and while the app is in background/killed?

spiritinlife commented 3 years ago

Haven't had the time to test it unfortunately.

On Thu, 4 Mar 2021 at 16:00, kvs notifications@github.com wrote:

hi @spiritinlife https://github.com/spiritinlife

Have you already tried to use this package with observing queries on and while the app is in background/killed?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/VictorKachalov/health_kit_reporter/issues/3#issuecomment-790637902, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRDBJ64NG6YH4NWY6GZYVTTB6HABANCNFSM4UR4DIZQ .

rologr35 commented 2 years ago

@VictorKachalov I've been testing ObserverQuery while the app is killed but I can't make it work properly. I already enable background capabilities and even init the observer as an isolated function in the main method of the app. I can say it was working a few times while the app is killed but after waiting some time it stops working properly. Thanks in advance

sangle1996 commented 1 year ago

I tried this https://github.com/nanoglobal/nano_healthkit, and it working fine even when the app killed However, it is too old and has been a long time didn't update

danielrnuttall commented 1 year ago

Hi all

Is there any update one this issue? Having background functionality even when the app is killed would be extremely useful. I see the README states it should work when the app is killed (is that still true?), because I have tested when the app is killed but the ObserveryQuery doesn't seem to work then. Only when the app is either open or in the background.

marinosabijan commented 10 months ago

I am also wondering if the background functionality is working realiably?