JohanDegraeve / xdripswift

xdrip for iOS, written in Swift
GNU General Public License v3.0
327 stars 320 forks source link

Live activity #446

Closed miguelpruivo closed 3 months ago

miguelpruivo commented 1 year ago

Can we have live activity to have the BG always on the screen like we have for example in other apps? That adds a nice convenience to the app. People with dynamic island also would have the BG always in it.

julesjwoods commented 1 year ago

Yeah, although xDrip is all round a significantly better app, this is a game changer of a feature used in GlucoseDirect.

miguelpruivo commented 1 year ago

Yeah, although xDrip is all round a significantly better app, this is a game changer of a feature used in GlucoseDirect.

Yeah, that's where I saw it in the first place, but reverted back to xDrip because of the alarms customization that GlucoseDirect doesn't have

paulplant commented 1 year ago

OK... on the list

aug0211 commented 4 months ago

@paulplant it looks like this is disabled for anyone in follower mode. Wondering if it could be enabled for those in follower mode?

paulplant commented 4 months ago

It's disabled for follower modes that are using the background audio keep-alive because it won't allow them to update.

I added a check to allow them to be enabled for follower modes when using an external heartbeat to wake the app up.

aug0211 commented 4 months ago

Oh, background audio won’t allow it up update? I hadn’t realized that.

If the push alerts work, would live activity also work?

aug0211 commented 4 months ago

I haven't done much with live activities before, maybe a simple question - but does the developer mode toggle that works for widget updates also allow live activity to update on the increased dev cycle (perhaps with xDrip set to use the aggressive audio backgrounder)?

paulplant commented 4 months ago

Oh, background audio won’t allow it up update? I hadn’t realized that. Live activities cannot update for an app that is in the background. The silent audio works to partially wake the app up enough to quickly process follower downloads and trigger alarms, but the app is still officially in a background state.

If the push alerts work, would live activity also work? I'm not sure what you mean? Do you mean APNs? How is that related?

paulplant commented 4 months ago

I haven't done much with live activities before, maybe a simple question - but does the developer mode toggle that works for widget updates also allow live activity to update on the increased dev cycle (perhaps with xDrip set to use the aggressive audio backgrounder)?

I don't follow your question, sorry.

Setting WidgetKit in Developer mode allows you to basically ignore refresh constraints but this isn't really noticeable anyway for Live Activities. They are allowed very frequent updates.

It's only really noticeable for standard iOS widgets (but only just) and definitely for WatchOS widgets (complications).

But it's not related to anything to do with background keep-alive.

Can you explain what it is you're trying to figure out?

aug0211 commented 4 months ago

Sure, sorry. Like I said, I have not done much with live activity before so my questions may not be going the right direction 😅

What I’m going after is live activities in follower mode without a heartbeat. Eg, a caregiver following a kiddo, and getting live activities on the caregiver device.

I was hoping that the same way we can get semi-reliable updates for widgets and for push alerts that we could get live activities updating semi-regularly in follower mode.

I thought perhaps the same triggers used for widget refreshes or push notifications could be useful for live activities. I also wasn’t sure if live activities leverage the same iOS refresh cadence policies as widgets, and if so, if the developer widget refresh toggle might help.

paulplant commented 4 months ago

Live activities won't work in follower mode without a heartbeat. If they could, we wouldn't have purposefully disabled them.

Although all are spawned from the WidgetKit framework, the constraints are very different. Live activities are designed for frequent updates but are not supposed to be permanently used in the way we are using them. The developer toggle won't make any difference as it is for a different thing than you're talking about.

It would be possible to wake up the app and update the live activities in the background if we were pushing values to the app from a web service via APNs, but that isn't the case with xDrip4iOS.

An easy way to get around this would be to use a RileyLink or EmaLink and carry it around in your pocket and use it as an external heartbeat for xDrip4iOS. I've tested this and it works perfectly.

aug0211 commented 4 months ago

Thanks Paul for helping me learn some. I've also dug up some documentation on live activities to learn more (eg, I didn't know they could run for up to 8 hours, that seems promising somehow).

I also took your advice and went ahead and ordered an OrangeLink Pro for now. Hopefully there's a creative option that emerges in time.

aug0211 commented 4 months ago

@paulplant, curious if you know of any documentation (or maybe a patch is needed?) to unlock using an OrangeLink as my heartbeat for a Follower (parent/caregiver) device. Or if you could point me in the direction for how you did this when you tested with it.

I purchased an OrangeLink Pro, but cannot find a way to add it in to xDrip4iOS as a heartbeat device. I may have missed this in published docs, sorry if so!

paulplant commented 4 months ago

Looking at your chart, it looks like you have duplicated readings. Please tap the BG Readings button at the top left of the Home Screen (2nd icon) and show us if this is the case.

Are you sure your master device is not uploading to Nightscout from two apps at the same time?

Actually, just checked the Nightscout URL (you can double tap this to hide it for 10 seconds to take screenshots)... you have duplicate readings being uploaded every 5 minutes:

image
aug0211 commented 4 months ago

Yes 100% this was it! I’m sorry I discovered this and tried to delete my comment before you spent any time looking at it 🤦‍♂️

The issue was I had NS enabled on the master device, so it was uploading in addition to iAPS. I turned off NS upload and this resolved it.

I have seen some occasions where BG delta reports oddly as +0 when it’s actually a -1 or +1, but haven’t gathered enough info around that yet. Figured I share since we’re talking about it here, but I think it’s unrelated/a different scenario. If I recall correctly, the live activity and widget had this issue but I think maybe the main view did not. I’ll watch and gather more info!

Thanks again Paul!

aug0211 commented 4 months ago

Ok, I got a bit more info. We had pretty steady BG this AM with a handful of small deltas like -1, and that seemed to trigger the inaccurate delta of +0 being reported.

Let me know if you'd like me to create another issue for this one. I've noticed it in Live Activity displays/Widget, iOS Standby display, and the app main display mode.

The issue is xDrip4iO5 displays a BG delta of +0 across all surfaces when it is in fact not +0.

It is reproducible and consistent in most (not all!?) cases of -1s I've been able to see (maybe 3-5 so far today and 5-10 overall). Other deltas seem accurate (not 100% confident on +1, haven't been able to spot that yet, but others like +5 or -8 etc look fine).

I confirmed only one device is uploading to NS.

Included screen shots below showing the +0 reported by xDrip4iO5, whereas Nightscout correctly shows the delta of -1.imageimage

paulplant commented 4 months ago

Can you click the BG Readings view (the drop icon on the Home Screen), screenshot it, then click the two readings that are from the above screenshots and screenshot the details screen for each one.

aug0211 commented 4 months ago

Here's a +1 delta example. Maybe this should be a separate issue, as it doesn't seem to be limited to only Live Activities. Let me know if you want me to create a different issue.

Screen shots below showing main Home Screen/widget/Live Activity from xDrip4iO5 showing +0, alongside Nightscout (via browser) and Dexcom (via LoopFollow) showing the actual +1.

Poking around a bit in the code to see if I can pinpoint this but no luck yet. I see some logic for handling corner cases around 0 but nothing jumping out yet.

Here are the two most recent readings from MongoDB database as well. All looks in order to me there.

9:50 AM

{"_id":"82BBE7DB-5670-4A87-85ED-3C702E5D0279","date":{"$numberDouble":"1713883839850.0"},"direction":"Flat","dateString":"2024-04-23T14:50:39.850Z","sgv":{"$numberInt":"103"},"glucose":{"$numberInt":"103"},"type":"sgv","activationDate":"2024-04-19T12:02:21.562Z","sessionStartDate":"2024-04-19T12:27:21.562Z","unfiltered":{"$numberInt":"103"},"utcOffset":{"$numberInt":"0"},"sysTime":"2024-04-23T14:50:39.850Z"}

9:45 AM

{"_id":"AE0C990D-536F-44B7-A082-E653EE24B2AC","dateString":"2024-04-23T14:45:38.574Z","unfiltered":{"$numberInt":"102"},"sgv":{"$numberInt":"102"},"date":{"$numberDouble":"1713883538573.0"},"type":"sgv","direction":"Flat","glucose":{"$numberInt":"102"},"activationDate":"2024-04-19T12:02:21.562Z","sessionStartDate":"2024-04-19T12:27:21.562Z","utcOffset":{"$numberInt":"0"},"sysTime":"2024-04-23T14:45:38.574Z"}

imageimageimageimageimage

aug0211 commented 4 months ago

imageimageimage

aug0211 commented 4 months ago

Some other interesting info I thought of that might be helpful:

paulplant commented 4 months ago

Nice info... thanks!!

aug0211 commented 4 months ago

I'm curious, do we know if I'm the only one who has seen this? Wondering if others in Follow mode have noticed it.

paulplant commented 4 months ago

I'm running two versions in parallel. My master app uploading to Nightscout, and a follower downloading the same values from Nightscout... and the deltas are always (so far) correct and aligned... I've been running it like this for 3 days and I've never noticed a difference.

Do you think you could share your Nightscout URL with so that I can try it and try to figure out what is going on? You can send it by e-mail to xdrip@proximus.be

aug0211 commented 4 months ago

Interesting! Just sent it.

aug0211 commented 4 months ago

You're looking at the +1 and -1 cases right? That's where I see false +0s.

aug0211 commented 4 months ago

I think I had some that were accurate when I uploaded from xDrip rather than from iAPS. For a bit I thought they were all correct - but I did still manage to spot a few that were off.

aug0211 commented 3 months ago

@paulplant (edited, I kept tagging Johan, lol) heads up, updated to latest release today (on master branch). I'm using the Heartbeat method you helped me with (thank you again, total game changer).

I've lost widgets, live activities, and watch complications on my device since updating.

I've tried flipping to master then back to follower, turning off/on live activities in iOS settings, turning off/on live activities in xDrip, re-installing app (on phone and watch), removing and re-adding my heartbeat, etc; but no luck.

It seems like xDrip is no longer recognizing me as "allowed" to use widgets/live activities. I recall there are some checks to prevent invalid scenarios (follower without a heartbeat). Maybe I'm somehow caught up in that check.

Master or Follower: Follower Follower Data Source: Nightscout Background Keep-alive: Heartbeat 🩶

Live Activities: Always Live Activity Size: Large

Let me know if other info would be helpful to provide.

aug0211 commented 3 months ago

IMG_3297 IMG_3298 IMG_3299 IMG_3300 IMG_3301 incoming-5653BF7A-8805-4F89-A932-3DBC76134037

aug0211 commented 3 months ago

Intersting, tapping the dynamic island DOES launch the app.

It seems like it's in the dynamic island, but does not show any data. Dynamic island is just black, not showing any BG data.

paulplant commented 3 months ago

Change the schema to xDrip Widget and rebuild

aug0211 commented 3 months ago

Just saw above note - deploying latest commit from "xdrip" scheme breaks, and then re-deploying latest commit from "xDrip Widget Extension" fixes the issue.

I think a single deployment from the main "xdrip" scheme is probably desired, not sure though. Thanks for the help with this workaround.

paulplant commented 3 months ago

Thanks for this. I'll look into it 👍

paulplant commented 3 months ago

Can you try and disable the Address Sanitizer function from the xDrip scheme -> Run -> Diagnostics?

And try and build the xDrip scheme and check that the widget extension is now installed correctly?

image image
aug0211 commented 3 months ago

Absolutely. Will check. Kiddo birthday party now and didn't think to bring the laptop. Later tonight I expect!

aug0211 commented 3 months ago

@paulplant (edited, I kept tagging Johan, lol) this appears to have fixed it.

paulplant commented 3 months ago

OK thanks. So confirmed for #536