0

I am developing a Screen Time App for iOS and I am having issues with the ShieldConfigurationExtension (ShieldConfigurationDataSource). I know this extensions is sandboxed but I should be able to read data from the main app.

I am using SwiftData as my database, but I am unable to initialize it in the extensions with an error indicating insufficient file permissions. I have App Group set up and I am able to share data using UserDefaults but that is just inconvenient.

Is there any way I could just open the SwiftData in read only mode so that I could display the user some info on the shield?

  • SwiftData Init:
 private func setupContainer() throws {
        
        let schema = Schema([
            DogEntity.self,
            HouseEntity.self
        ])
        
        // Use app group container if available
        let config: ModelConfiguration
        
        if let containerURL = FileManager.default.containerURL(
            forSecurityApplicationGroupIdentifier: "group.\(Bundle.app.bundleIdentifier ?? "")"
        ) {
            config = ModelConfiguration(schema: schema, url: containerURL.appendingPathComponent("default.sqlite"))
        } else {
            config = ModelConfiguration(schema: schema)
        }
        
        self.container = try ModelContainer(for: schema, configurations: [config])
    }
  • Error in extension:
Copy Code
fault: Attempt to add read-only file at path file:///private/var/mobile/Containers/Shared/AppGroup/51431199-5919-4AE6-940C-6FE3C53EEB46/default.sqlite read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.
 
error: (3) access permission denied
 
error: Encountered exception error during prepareSQL for SQL string 'SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'' : access permission denied with userInfo {
    NSFilePath = "/private/var/mobile/Containers/Shared/AppGroup/51431199-5919-4AE6-940C-6FE3C53EEB46/default.sqlite";
    NSSQLiteErrorDomain = 3;
} while checking table name from store: <NSSQLiteConnection: 0x154100300>
 
error: Store failed to load.  <NSPersistentStoreDescription: 0x15402d590> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/51431199-5919-4AE6-940C-6FE3C53EEB46/default.sqlite) with error = Error Domain=NSCocoaErrorDomain Code=256 "The file “default.sqlite” couldn’t be opened." UserInfo={NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/51431199-5919-4AE6-940C-6FE3C53EEB46/default.sqlite, NSSQLiteErrorDomain=3} with userInfo {
    NSFilePath = "/private/var/mobile/Containers/Shared/AppGroup/51431199-5919-4AE6-940C-6FE3C53EEB46/default.sqlite";
    NSSQLiteErrorDomain = 3;
}

Any help appreciated 🙂

3
  • There is an init method for ModelConfiguration that takes an allowsSave parameter, maybe try that one instead. Commented May 30, 2025 at 9:12
  • Yes, I know about it. I tried it too, also tried using the init with groupContainer instead of the URL and also tried just default init to create a new database and everything failed with the exact same error. :( Commented Jun 2, 2025 at 7:25
  • How did you even get this error? I can't debug the screen time extensions at all. Commented Oct 21, 2025 at 18:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.