fix(ios): avoid TCC prompt on Mac Catalyst by using Application Support#1967
Open
skrtdev wants to merge 1 commit into
Open
fix(ios): avoid TCC prompt on Mac Catalyst by using Application Support#1967skrtdev wants to merge 1 commit into
skrtdev wants to merge 1 commit into
Conversation
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)
There was a problem hiding this comment.
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_MACCATALYSTbranch 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Mac Catalyst the app process is unsandboxed and
NSDocumentDirectoryresolves to the user's~/Documentsfolder. The first time the app reads or writes anything there, macOS shows the TCC prompt: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.
NSApplicationSupportDirectoryresolves to~/Library/Application Support, which is per-app, private to the bundle, and exempt from TCC. Storing the database under<App Support>/<bundleIdentifier>/<dbName>.dbkeeps 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>.dband copy it over. Doing that probe would itself trigger the TCC prompt this fix is meant to avoid — defeating the whole point.~/Documentsand 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
resolveDatabasePath/pathForNamereturn the same~/Documents/<dbName>.dbpaths as before.~/Library/Application Support/<bundleId>/<dbName>.db.🤖 Generated with Claude Code