I am building a simple iOS app that shows the total phone usage time for today using the Screen Time APIs.
Architecture:
Main app
→ requests authorization using AuthorizationCenter.shared.requestAuthorization(for: .individual)
→ displays a DeviceActivityReport
Report extension
→ DeviceActivityReportExtension
→ calculates total usage using DeviceActivityResults<DeviceActivityData>
→ shows the number in a SwiftUI view
The report works correctly. The extension successfully calculates the total usage and displays it on screen.
Example logic inside the report extension:
for await activityData in data {
for await segment in activityData.activitySegments {
totalSeconds += segment.totalActivityDuration
}
}
let totalMinutes = Int(totalSeconds / 60)
The problem:
I need the main app to access that number so I can store it daily in my own database.
I tried to send the value from the extension to the main app using:
- App Group +
UserDefaults(suiteName:) - App Group + shared file (
FileManager.containerURL) - writing inside
makeConfiguration(...)
Example:
if let defaults = UserDefaults(suiteName: "group.myapp") {
defaults.set(value, forKey: "savedTotalActivity")
}
But the main app cannot read the value. The report extension displays the number correctly, but the data never appears in shared storage.
Questions:
- Is
DeviceActivityReportExtensionintentionally sandboxed so Screen Time data cannot be exported to the containing app? - Is there any supported way for the main app to access the total usage value calculated in the report extension?
- If exporting the value is restricted, what is the recommended architecture for apps that want to store daily Screen Time totals for later analysis?
Goal:
I want a simple app that records something like:
2026-03-08 → 244 minutes
2026-03-09 → 198 minutes
and stores it inside the app database.
Any guidance on the correct architecture would help.