Skip to content

Using the library on TvOS fails #469

@joseph-elmallah

Description

@joseph-elmallah

Description

When setting up a SQL database on tvOS, I always get an error
You don’t have permission to save the file “Application Support” in the folder “Library”.
Error Domain=NSCocoaErrorDomain Code=513

Looking at the code I realize, in many places the library attempt to create

try FileManager.default.createDirectory(
      at: .applicationSupportDirectory,
      withIntermediateDirectories: true
    )

like in Metadatabase.swift, SyncEngine.swift and in DefaultDatabase.swift
These calls will always fail because tvOS apps can't have a support directory.

When I switch to in memory database, some of the errors disappear except the SyncEngine's.
When called, the SyncEngine will try to create a defaultMetadatabase that in turn will try to create the applicationSupportDirectory. This will throw and the entire sync engine initialization fails.

For tvOS I think the best case scenario is to use .cachesDirectory and if the OS purges it, then on next App launch all data will be re-downloaded from iCloud.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • I have determined whether this bug is also reproducible in a vanilla GRDB project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Allow the use of different folders on tvOS, like the .cachesDirectory to avoid always throwing an error.

Actual behavior

on tvOS the library always fails with an error You don’t have permission to save the file “Application Support” in the folder “Library”. when using a SyncEngine and iCloud.

Reproducing project

  1. Setup a Vanilla project.
  2. Import SQLData
  3. Configure an iCloud identifier and setup your project with it.
  4. Create a basic Database initialization (like in the docs) + configure a Sync Engine (keep everything vanilla)
  5. Run on a real tvOS (on a simulator this will succeed)

SQLiteData version information

1.6.1

Sharing version information

2.8.0

GRDB version information

7.10.0

Destination operating system

tvOS 26.5

Xcode version information

26.5

Swift Compiler version information

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions