Skip to content

Fix watch crash when changing pages - #2631

Merged
ps2 merged 1 commit into
next-devfrom
fix/watch-extension-delegate-shared
Oct 31, 2026
Merged

ps2 merged 1 commit into
next-devfrom
fix/watch-extension-delegate-shared

Conversation

@ps2

@ps2 ps2 commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

On next-dev, the watch app crashes as soon as you swipe between pages.

ExtensionDelegate.shared() looked up WKApplication.shared().delegate. Under the SwiftUI app lifecycle (@WKApplicationDelegateAdaptor) that property is nil, so the implicitly unwrapped accessor trapped. The usage recording added in #2629 calls shared() from SwiftUI views: page changes in ContentView, and the carbs, bolus, presets and carb list buttons. Each of those crashed the watch app.

The delegate now stores itself in init, and shared() returns that instance.

Testing

  • Watch simulator, next-dev e0eb985: the first page swipe crashes with EXC_BREAKPOINT in ExtensionDelegate.shared() (ExtensionDelegate.swift:29), called from ContentView.swift:56.
  • With this change: swiping back and forth between pages doesn't crash, and the swipes show up in the usage summary's screenCounts (actions: 1, chart: 2).
  • To reach the pages without a paired phone, I temporarily bypassed the onboarding check in LoopWatchApp. That edit is not part of this PR.

ExtensionDelegate.shared() looked up WKApplication.shared().delegate,
which is nil under the SwiftUI app lifecycle, so it trapped. The usage
recording added in #2629 calls it from SwiftUI views, so swiping
between pages, or opening carbs, bolus or presets, crashed the watch
app. The delegate now records itself when it is created.
@ps2
ps2 marked this pull request as ready for review October 31, 2026 19:50
@ps2
ps2 merged commit be863cd into next-dev Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant