Skip to content

Store Tracks Core Data DB in Caches on tvOS#361

Merged
kean merged 2 commits into
trunkfrom
fix/tvos-store-directory
Jun 11, 2026
Merged

Store Tracks Core Data DB in Caches on tvOS#361
kean merged 2 commits into
trunkfrom
fix/tvos-store-directory

Conversation

@kean

@kean kean commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

TracksContextManager creates its Core Data SQLite store under Application Support, which isn't writable on tvOS (only Caches and tmp are). On a real Apple TV, TracksService init throws TracksApplicationSupportException / TracksPersistentStoreException. The tvOS Simulator hides this (it inherits the Mac filesystem), so it only fails on device.

Fix

Route the store's base directory to NSCachesDirectory on tvOS, keeping Application Support on every other platform. The store becomes Library/Caches/<bundleid>/Tracks.sqlite on tvOS. Caches is purgeable, which is fine for the transient Tracks event queue (events are flushed to the server). Also made the directory-creation error text platform-neutral and the store-directory test platform-aware.

Testing

testStoreIsInExpectedDirectory passes on tvOS (store under Caches) and macOS (Application Support); build-for-testing succeeds for the tvOS Simulator.


  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

🤖 Generated with Claude Code

kean and others added 2 commits June 11, 2026 11:12
tvOS sandboxes apps so that only the Caches and temporary directories are
writable; Application Support is not. TracksContextManager created its Core
Data SQLite store under Application Support, which throws
TracksApplicationSupportException / TracksPersistentStoreException when
TracksService initializes on Apple TV. (The tvOS Simulator masks this because
it inherits the Mac filesystem, so the store only fails on real hardware.)

Route the store's base directory to Caches on tvOS, keeping Application Support
on all other platforms. The per-bundle-identifier subfolder and directory
creation are unchanged, so the store becomes Library/Caches/<bundleid>/Tracks.sqlite
on tvOS. Caches is purgeable, which is acceptable for the Tracks event queue
since events are flushed to the server. Also make the directory-creation error
messages platform-neutral and the store-directory test platform-aware.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
These private helpers now resolve to Caches on tvOS (not Application
Support), so the old names were misleading. Rename to platform-neutral,
store-oriented names: storeBaseDirectoryURL, storeDirectoryURLForContainerApp,
and storeDirectoryURLForAppWithBundleIdentifier:.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@SergioEstevao SergioEstevao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@kean
kean merged commit b248d4a into trunk Jun 11, 2026
5 checks passed
@kean
kean deleted the fix/tvos-store-directory branch June 11, 2026 18:14
pull Bot pushed a commit to Mu-L/pocket-casts-ios that referenced this pull request Jun 11, 2026
Point the Tracks dependency at the commit that stores the Tracks Core Data
DB in Caches on tvOS, where Application Support is not writable, so the
analytics pipeline no longer throws at TracksService init on Apple TV.

Depends on Automattic/Automattic-Tracks-iOS#361.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants