fix(ios): restore last-selected NWC ambient track on launch

This commit is contained in:
Evan Kaloudis
2026-06-05 14:09:20 -04:00
parent 47a2fffe57
commit 47e218b889
+10 -1
View File
@@ -117,7 +117,16 @@ RCT_EXPORT_MODULE();
_hasListeners = NO;
_disconnectCount = 0;
_trackNames = [NWCAmbientTracks trackNames];
_currentTrackIndex = 0;
// Restore last-selected track from the app group (written by
// switchToTrackAtIndex: via NWCLiveActivityBridge). UserDefaults
// returns 0 if the key was never written, which matches the default.
NSInteger persisted = [NWCLiveActivityBridge appGroupTrackIndex];
NSInteger count = (NSInteger)_trackNames.count;
_currentTrackIndex = (count > 0 && persisted >= 0 && persisted < count)
? persisted
: 0;
_isMuted = NO;
_iosVersion = [[UIDevice currentDevice] systemVersion];
_deviceModel = [self deviceModelIdentifier];