Unable to save data from Device Activity Report Extension in CoreData

I implemented an app in SwiftUI using Screen Time API, which can show apps usage duration from Device Activity Report Extension. Device Activity Report Extension is a separate target.

Now I want to save those data into CoreData from Device Activity Report Extension and fetch that from my main app target. How can I Achieve that ?

You won't be able to do that. Your Device Activity Report extension runs in a sandboxed environment to protect user privacy. As stated in the documentation, "this sandbox prevents your extension from making network requests or moving sensitive content outside the extension’s address space".

What this means is that even if you place your Core Data database in an app group container that is shared between your app and extension, you won't be able to write anything to it from the extension. You might be able to read from it, though I have never tried this with Core Data.

Unable to save data from Device Activity Report Extension in CoreData
 
 
Q