Open spiritinlife opened 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
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
I will also present some changes in event handling in new version
@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.
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.
hi @spiritinlife
Have you already tried to use this package with observing queries on and while the app is in background/killed?
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 .
@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
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
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.
I am also wondering if the background functionality is working realiably?
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?