TestFlight diagnostic build: HealthKit logging + permission fixes - #30
Draft
gsbernstein wants to merge 5 commits into
Draft
TestFlight diagnostic build: HealthKit logging + permission fixes#30gsbernstein wants to merge 5 commits into
gsbernstein wants to merge 5 commits into
Conversation
- DiagnosticLogger records HealthKit bootstrap, queries, and state changes. - Settings Diagnostics section: share/copy logs, retry HealthKit, live state. - Grant Access always calls requestAuthorization and shows loading/errors. - Bootstrap tries silent data load first; only prompts when zero samples. - Await HK queries, recover from SwiftData store failures, fix preferences seeding. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Make log() nonisolated so it can be called from BedtimeApp's static ModelContainer initializer. Move UI-published mutations to @mainactor record() and remove init-time logging that referenced shared during init. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Present UIActivityViewController from the topmost view controller instead of nesting a SwiftUI sheet inside the Settings sheet. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Master rewrote HealthKitManager to use HKSampleQueryDescriptor / HKSourceQueryDescriptor with proper awaiting (#40), added an observer query with background delivery, and already carries the SwiftData store-reset recovery. Kept all of that and re-applied the diagnostics layer on top: - DiagnosticLogger instrumentation across container open, auth, queries, source discovery, sample processing, and permission state transitions. - requestAccessFromUser() for Grant Access / Settings retry, which always re-presents the HealthKit prompt instead of short-circuiting once asked. - Settings Diagnostics section with share/copy logs and retry, now also reloading available sources after a retry. Dropped the superseded fetchSleepDataForDisplay/discoverAvailableSources continuation wrappers in favor of master's descriptor-based queries. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
TestFlight diagnostic build for a tester who cannot load HealthKit sleep data. Adds local logging with a share/copy flow in Settings — no third-party analytics.
Now merged up to date with
master, which independently rewroteHealthKitManagerto useHKSampleQueryDescriptor/HKSourceQueryDescriptorwith proper awaiting (#40), added an observer query with background delivery, and already carries the SwiftData store-reset recovery. All of that is kept; the diagnostics layer is re-applied on top.What this adds
DiagnosticLogger— in-memory log (capped at 500 entries) coveringModelContaineropen, HealthKit availability and authorization, sample queries, source discovery, sample processing, and permission state transitions.requestAccessFromUser()— backs Grant Access and the Settings retry. UnlikerequestAuthorization(), it always re-presents the HealthKit prompt instead of short-circuiting once the app has asked before, shows a spinner, and surfaces errors. When the reload returns zero samples it points the user at Settings → Health → Data Access & Devices.SharePresenter— presentsUIActivityViewControllerfrom the topmost view controller. Nesting a SwiftUI.sheetinside the Settings sheet caused the share sheet to dismiss itself and take Settings with it.For the tester
Reading the logs
requestAuthorization returnedfollowed byrawSamples=0suggests read access is denied — check Settings → Health → Data Access & Devices → Bedger → SleepSleep sample query failed: …is an actual HealthKit error with its messageDiscovered N sourceswith N > 0 but 0 sessions after filtering points at source exclusions or sleep-stage parsingNote
ContentViewstill insertsUserPreferencesfrom a computed property read duringbodyevaluation (inherited frommaster). That is a latent SwiftUI/SwiftData issue, not the cause of the reported crash — the crash log pointed at theModelContainerfatalError, whichmasternow recovers from. Worth fixing separately against currentmaster.