Commit 8a8ae68
fix(ios): reconnect to Mac when returning to the foreground
Reported as "Code Island Buddy keeps disconnecting when app minimized or
iPhone closed" (#261). Root cause: the MultipeerConnectivity session that
carries the rich, foreground status (the "Mac connected" state ContentView
shows) is torn down by iOS whenever the app is backgrounded or the phone
is locked — that part is expected, standard platform behavior for
Wi-Fi/Bonjour-based connectivity, not a bug, and it's exactly why a
separate Bluetooth channel already exists for background Live
Activity/Watch summaries (bluetooth-central is already declared in
Info.plist and works as designed).
The actual bug: nothing ever told the browser to restart afterwards.
`ContentView`'s `.onAppear { connection.start() }` runs once, when the
view first appears, not on every return to the foreground, and `start()`
itself no-ops once `browsing` is already (stale-)true. So after any
background/foreground cycle the app was stuck showing "disconnected"
until the user manually tapped the search toggle — indistinguishable from
"keeps disconnecting" to a user who never touches that button.
Fix: observe `scenePhase` at the App level and, only on a real
background -> active transition (not initial launch) with no connected
peer, force a clean stop()+start() of discovery. No-ops whenever the
connection is already healthy.
Verified via full `xcodebuild` (all targets, complete embedded app).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent d716c2b commit 8a8ae68
2 files changed
Lines changed: 28 additions & 0 deletions
File tree
- ios/CodeIslandCompanion/CodeIslandCompanion
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
103 | 123 | | |
104 | 124 | | |
105 | 125 | | |
| |||
0 commit comments