Skip to content

fix(ios): avoid TCC prompt on Mac Catalyst by using Application Support#1967

Open
skrtdev wants to merge 1 commit into
Nozbe:masterfrom
skrtdev:fix/mac-catalyst-application-support
Open

fix(ios): avoid TCC prompt on Mac Catalyst by using Application Support#1967
skrtdev wants to merge 1 commit into
Nozbe:masterfrom
skrtdev:fix/mac-catalyst-application-support

Conversation

@skrtdev
Copy link
Copy Markdown

@skrtdev skrtdev commented May 21, 2026

Summary

On Mac Catalyst the app process is unsandboxed and NSDocumentDirectory resolves to the user's ~/Documents folder. The first time the app reads or writes anything there, macOS shows the TCC prompt:

"App would like to access files in your Documents folder"

WatermelonDB opens the SQLite database at launch — before any UI is on screen — so on every cold launch Catalyst users see this prompt as the very first thing the app does. There's no good way to dismiss-for-good without granting Documents-folder access to the entire app, which most apps don't actually need.

NSApplicationSupportDirectory resolves to ~/Library/Application Support, which is per-app, private to the bundle, and exempt from TCC. Storing the database under <App Support>/<bundleIdentifier>/<dbName>.db keeps the launch flow prompt-free.

Change

Both location helpers learn a Catalyst branch gated on #if TARGET_OS_MACCATALYST:

  • DatabasePlatformIOS.mm::resolveDatabasePath (C++ entry point used by the new C++/JSI bridge)
  • WMDatabaseDriver.m::pathForName (Obj-C driver entry point used by the legacy bridge)

iOS and iPadOS code paths are unchanged.

Migration

We intentionally do not probe for a legacy file at ~/Documents/<dbName>.db and copy it over. Doing that probe would itself trigger the TCC prompt this fix is meant to avoid — defeating the whole point.

  • Catalyst-only apps starting fresh get a clean Application Support location.
  • iOS apps that ship a Catalyst build alongside keep their iOS database at ~/Documents and create a separate Catalyst database under Application Support on first Catalyst launch.

For apps that genuinely need to migrate an existing Catalyst database, the application layer can do this with full user consent (e.g. an explicit "Import from previous version" button).

Test plan

  • Build for iOS Simulator — resolveDatabasePath / pathForName return the same ~/Documents/<dbName>.db paths as before.
  • Build for Mac Catalyst — both helpers return ~/Library/Application Support/<bundleId>/<dbName>.db.
  • Cold launch the Catalyst build with no prior database — no TCC prompt; database is created under Application Support.
  • Persist data, relaunch — database is reopened correctly under Application Support.

🤖 Generated with Claude Code

On Mac Catalyst, the app process is unsandboxed and
NSDocumentDirectory resolves to the user's ~/Documents folder. The
first time the app touches anything inside that folder, the macOS
TCC subsystem shows a "App would like to access files in your
Documents folder" prompt — which fires the moment the database is
opened at launch, before any UI is on screen.

NSApplicationSupportDirectory resolves to
~/Library/Application Support, which is per-app, private to the
bundle, and exempt from TCC. Storing the WatermelonDB SQLite file
under <App Support>/<bundleIdentifier>/<dbName>.db keeps Mac
Catalyst users from being prompted at every cold launch.

Behaviour on iOS and iPadOS is unchanged (the new branch is gated
to `#if TARGET_OS_MACCATALYST`).

We intentionally do not migrate from the legacy ~/Documents path:
probing for a legacy file would itself trigger the TCC prompt we
are trying to avoid. Catalyst-only apps starting fresh get a clean
location; existing iOS apps that ship a Catalyst build alongside
keep their iOS database at ~/Documents and a separate Catalyst
database under Application Support.

Both location helpers are touched:
- DatabasePlatformIOS.mm::resolveDatabasePath (C++ entry point)
- WMDatabaseDriver.m::pathForName (Obj-C driver entry point)
Copilot AI review requested due to automatic review settings May 21, 2026 11:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the default SQLite database location for Mac Catalyst builds to avoid triggering the macOS TCC “Documents folder access” prompt at cold launch by using Application Support instead of NSDocumentDirectory. This affects both the legacy Obj-C driver path resolver and the newer C++/JSI resolver; iOS/iPadOS behavior remains unchanged.

Changes:

  • Add a TARGET_OS_MACCATALYST branch to store DBs under ~/Library/Application Support/<bundleId>/<dbName>.db.
  • Keep iOS/iPadOS default behavior (Documents/<dbName>.db) unchanged.
  • Explicitly avoid legacy-path probing/migration to prevent triggering the very prompt this change is meant to eliminate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
native/ios/WatermelonDB/objc/WMDatabaseDriver.m Routes legacy driver DB path resolution to Application Support on Mac Catalyst.
native/ios/WatermelonDB/DatabasePlatformIOS.mm Routes C++/JSI bridge DB path resolution to Application Support on Mac Catalyst.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +48
NSURL *appSupport = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES
error:nil];
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier] ?: @"WatermelonDB";
NSURL *dir = [appSupport URLByAppendingPathComponent:bundleId isDirectory:YES];
[[NSFileManager defaultManager] createDirectoryAtURL:dir
withIntermediateDirectories:YES
attributes:nil
error:nil];
Comment on lines +46 to +49
[NSFileManager.defaultManager createDirectoryAtURL:dir
withIntermediateDirectories:YES
attributes:nil
error:nil];
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