Hi everyone,
I’m developing a parental control app using Apple's ScreenTime API, and I need to display ScreenTime data separately for each child in a family. The API offers options like .children
and .all
, but I’m looking for the best way to reliably filter and show data for a single child within the app.
I’ve seen other apps like Ohana successfully implement this feature, even the apple official family screen time feature has this where parents can view ScreenTime data for each child individually. I want to achieve a similar experience in my app, ensuring that if a parent selects "John," the app only displays John's ScreenTime, without mixing in data from his siblings.
Here’s the approach I’m considering using DeviceActivityFilter
and DeviceActivityReport
to target data for a specific child:
let filter = DeviceActivityFilter(
segment: .children,
intervals: .everyDay
)
let report = DeviceActivityReport(
filter: filter
) { (data) in
// Process and separate data for each child
if let activityData = data as? DeviceActivityReportData {
for child in activityData.children {
if child.name == "ChildName" { // Replace "ChildName" with the actual child's name or identifier
// Access and display data for the specific child
print("Child: \(child.name), Screen Time: \(child.screenTime)")
}
}
}
}
Context:
- Goal: I need to ensure parents can view ScreenTime data for each child individually, similar to how Ohana does it. For example, selecting "John" should display only John's ScreenTime.
- Challenge: While some data can be grouped within the DeviceActivity extension, I'm not entirely sure if this approach with
DeviceActivityFilter
is the most reliable way to isolate and display data for a single child.
Has anyone implemented a similar solution? Are there any alternative methods or best practices that could improve the accuracy and reliability of this filtering?
Any advice or examples would be greatly appreciated!
Thanks!