Post

Replies

Boosts

Views

Activity

Reply to Using core data in ShieldConfigurationExtension
I think it's quite likely that the sandbox is blocking access to Core Data. I'm using it via Swift Data: do { container = try ModelContainer( for: Settings.self, configurations: ModelConfiguration(allowsSave: allowsSave) ) context = ModelContext(container) } catch { fatalError("*** Failed to create BreakManager: \(error)") } I get an error when I try to create the ModelContainer: Failed to register for com.apple.managedconfiguration.effectivesettingschanged: 9 Could not register for user invalidated notifications; status = 9 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/<snip>/Library/Application Support/default.store"; NSSQLiteErrorDomain = 3; } while checking table name from store: <NSSQLiteConnection: 0x1010d4180> error: addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (256) error: userInfo: error: NSFilePath : /private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application Support/default.store error: NSSQLiteErrorDomain : 3 error: storeType: SQLite error: configuration: default error: URL: file:///private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application%20Support/default.store error: <NSPersistentStoreCoordinator: 0x1010f4230>: Attempting recovery from error encountered during addPersistentStore: 0x101025260 Error Domain=NSCocoaErrorDomain Code=256 "The file “default.store” couldn’t be opened." UserInfo={NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application Support/default.store, NSSQLiteErrorDomain=3} error: Store failed to load. <NSPersistentStoreDescription: 0x101025200> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application%20Support/default.store) with error = Error Domain=NSCocoaErrorDomain Code=256 "The file “default.store” couldn’t be opened." UserInfo={NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application Support/default.store, NSSQLiteErrorDomain=3} with userInfo { NSFilePath = "/private/var/mobile/Containers/Shared/AppGroup/<snip>/Library/Application Support/default.store"; NSSQLiteErrorDomain = 3; } Unresolved error loading container Error Domain=NSCocoaErrorDomain Code=256 UserInfo={NSFilePath=<private>, NSSQLiteErrorDomain=3} NSSQLiteErrorDomain corresponds to SQLite's own errors, and SQLite Error 3 is ERROR_PERM, for a permissions error. I can read and write to my App Group's container, including via UserDefaults, so it appears that the sandboxing mechanism in the Screen Time technology frameworks specifically restricts SQLite's permissions when working inside the sandbox. This is pretty frustrating, because the sandbox is only really to stop apps from getting data out of DeviceActivityReport, no reason it should break elsewhere. I've filed FB14915291 to track this.
Aug ’24
Reply to DeviceActivityMonitor Extension not working
I can get intervalDidStart to call (verified both through the debugger and by taking an obvious action; in my case shielding all apps), but eventDidReachThreshold won't. I am 99% sure this is because the iOS Simulator doesn't track DeviceActivity (at least, Settings > Screen Time on the Simulator never reports app usage); so the schedules themselves will run (including their lifecycle methods), but any lifecycle methods around events won't. Only workaround was to debug on device.
Feb ’24