From 4cd273c0762a3675cf2030a27219bbb9273b1eb2 Mon Sep 17 00:00:00 2001 From: Jonah Walker Date: Tue, 14 Jul 2026 14:56:01 -0400 Subject: [PATCH 1/2] fix: resolve getDatabasesPath under Library/Caches on tvOS Documents is not writable in the tvOS sandbox on physical devices, so the previous default failed every openDatabase with SQLITE_CANTOPEN (the simulator sandbox permits the write, masking it). Caches is the tvOS-writable location consistent with the platform's purgeable-storage model. --- packages/sqflite_tvos/README.md | 12 ++++++++---- packages/sqflite_tvos/tvos/Classes/SqflitePlugin.m | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/sqflite_tvos/README.md b/packages/sqflite_tvos/README.md index 2aab91c..f460e7a 100644 --- a/packages/sqflite_tvos/README.md +++ b/packages/sqflite_tvos/README.md @@ -23,10 +23,14 @@ dependencies: ships with tvOS. ### ⚠️ Limitations / differs from iOS -- Put the database under a `path_provider` directory (Documents / - Application Support). The tvOS sandbox is constrained and OS-managed - caches can be purged — don't store the DB in a cache/temp dir if you - need durability. +- On physical tvOS devices only `Library/Caches` and `tmp` are writable — + opening a database under Documents fails with `SQLITE_CANTOPEN` (the + simulator sandbox permits the write, masking this). The plugin's default + `getDatabasesPath()` resolves under `Library/Caches`, so the canonical + `openDatabase(join(await getDatabasesPath(), 'x.db'))` works on hardware. + Note tvOS storage is purgeable by platform contract: the OS may evict + Caches at any time, so data that must survive needs a server or iCloud + Key-Value Storage, not the local filesystem. ### ❌ Not supported on tvOS - None for core SQLite usage. diff --git a/packages/sqflite_tvos/tvos/Classes/SqflitePlugin.m b/packages/sqflite_tvos/tvos/Classes/SqflitePlugin.m index d9a004b..a77b0ae 100644 --- a/packages/sqflite_tvos/tvos/Classes/SqflitePlugin.m +++ b/packages/sqflite_tvos/tvos/Classes/SqflitePlugin.m @@ -760,10 +760,11 @@ - (void)handleOptionsCall:(FlutterMethodCall*)call result:(FlutterResult)result // // getDatabasesPath -// returns the Documents directory on iOS +// returns the Library/Caches directory on tvOS +// (the tvOS sandbox only allows writes to Caches and tmp) // - (void)handleGetDatabasesPath:(FlutterMethodCall*)call result:(FlutterResult)result { - NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); result(paths.firstObject); } From 3a9e84cabd02a35b64900df16d7d2613d173f7a4 Mon Sep 17 00:00:00 2001 From: Jonah Walker Date: Mon, 20 Jul 2026 14:08:26 -0400 Subject: [PATCH 2/2] chore(sqflite_tvos): bump to 0.0.2 with CHANGELOG entry for Caches path fix Requested in PR review: version bump so the fix can ship to pub.dev, and a CHANGELOG entry documenting the behaviour change for simulator-created databases under the old Documents path. Co-Authored-By: Claude Fable 5 --- packages/sqflite_tvos/CHANGELOG.md | 12 ++++++++++++ packages/sqflite_tvos/pubspec.yaml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/sqflite_tvos/CHANGELOG.md b/packages/sqflite_tvos/CHANGELOG.md index 57d1d64..80ca374 100644 --- a/packages/sqflite_tvos/CHANGELOG.md +++ b/packages/sqflite_tvos/CHANGELOG.md @@ -1,3 +1,15 @@ +## 0.0.2 + +* **Fix:** `getDatabasesPath()` now resolves under `Library/Caches` instead of + Documents. On a physical Apple TV the tvOS sandbox does not permit writes to + Documents, so the canonical + `openDatabase(join(await getDatabasesPath(), 'x.db'))` failed with + `SQLITE_CANTOPEN`. The simulator sandbox permits the write, which masked this. +* **Behaviour change:** apps that created a database against the simulator under + the old Documents path will resolve to a new, empty database. tvOS storage is + purgeable by platform contract — data that must survive belongs on a server or + in iCloud Key-Value Storage. + ## 0.0.1 Initial release — tvOS implementation of `sqflite` for diff --git a/packages/sqflite_tvos/pubspec.yaml b/packages/sqflite_tvos/pubspec.yaml index 60298fc..60e30b1 100644 --- a/packages/sqflite_tvos/pubspec.yaml +++ b/packages/sqflite_tvos/pubspec.yaml @@ -1,6 +1,6 @@ name: sqflite_tvos description: "tvOS (Apple TV) implementation of the sqflite Flutter plugin, provided by flutter-tvos." -version: 0.0.1 +version: 0.0.2 homepage: https://fluttertv.dev repository: https://github.com/fluttertv/plugins/tree/main/packages/sqflite_tvos issue_tracker: https://github.com/fluttertv/plugins/issues