DeviceActivityReport presents statistics for a device: https://developer.apple.com/documentation/deviceactivity/deviceactivityreport
The problem: DeviceActivityReport can present statistics with a delay for a parent device (when DeviceActivityReport is presenting, the DeviceActivityReportExtension is called to process the statistics). One possible solution is to call DeviceActivityReport periodically throughout the day in a child device. However, the app will not be available all day. Is there any way to run DeviceActivityReport in the background?
I have tried the following approach, but it didn’t work (DeviceActivityReportExtension didnt call):
let hostingController: UIHostingController? = .init(rootView: DeviceActivityReport(context, filter: filter))
hostingController?.view.frame = .init(origin: .zero, size: .init(width: 100, height: 100))
hostingController?.beginAppearanceTransition(true, animated: false)
hostingController?.loadView()
hostingController?.viewDidLoad()
try? await Task.sleep(for: .seconds(0.5))
hostingController?.viewWillAppear(true)
hostingController?.viewWillLayoutSubviews()
try? await Task.sleep(for: .seconds(0.5))
hostingController?.viewDidAppear(true)
try? await Task.sleep(for: .seconds(0.5))
hostingController?.didMove(toParent: rootVC)
try? await Task.sleep(for: .seconds(0.5))
hostingController?.viewWillLayoutSubviews()
hostingController?.viewDidLayoutSubviews()
hostingController?.view.layoutIfNeeded()
hostingController?.view.layoutSubviews()
hostingController?.endAppearanceTransition()
Is there any way to run DeviceActivityReport in the background? (when app is not visible/closed). The main problem is call DeviceActivityReport
Post
Replies
Boosts
Views
Activity
The data displayed about a child’s apps can be outdated (DeviceActivityReport), leading to misinformation for the user. When I access the “Screen Time” section (for child in the parent device) in the iPhone settings, I see there is an update functionality to force load the actual data.
I have tried various workarounds, such as attempting to force an update on the child’s device to call DeviceActivityReport and opening system settings, but none of these have been successful :(
How can I implement something similar? Is there a way to force update this data ?
Hello! I am developing an app using the Screen Time API. Everything is good, but I have a problem with DeviceActivityReport. On the child’s device, stats are synced to the app in about 1-5 minutes. However, on the parent’s device, it can take around an hour or more. How can I make the stats sync faster between the child’s device and the parent’s device?
How I Implemented It
@Published var context: DeviceActivityReport.Context = .init("Time Limit")
let filter = DeviceActivityFilter(
segment: .daily(
during: Calendar.current.dateInterval(of: .day, for: .now)!
),
users: .children,
devices: .all,
applications: applicationTokens
)
DeviceActivityReport(viewModel.context, filter: viewModel.filter)
.frame(maxHeight: viewModel.maxReportHeight)
In the Report Extension (Test Code)
for await d in data {
result += "device.name=\(d.device.name ?? "")"
result += "\nuser.appleID=\(d.user.appleID ?? "")"
result += "\ngivenName=\(d.user.nameComponents?.givenName ?? "")"
result += "\nrole=\(d.user.role.rawValue)"
for await activity in d.activitySegments {
result += "\nactivitySegments hashValue=\(activity.hashValue)"
result += "\ntotalActivityDuration=\(activity.totalActivityDuration)"
result += "\ndateInterval=\(activity.dateInterval)"
for await category in activity.categories {
result += "\ncategory=\(category.category.localizedDisplayName ?? "")"
for await app in category.applications {
result += "\napp=\(app.application.bundleIdentifier ?? ""), time=\(app.totalActivityDuration)"
}
}
}
}
Problems:
activity.categories can be empty for a long time
app.totalActivityDuration contains outdated information
I need to wait about 1+ hours to get “actual” information.
I want to create an app to control a child's device. As I understand it, I need to follow this logic:
I have one app for both the child and the parent.
For the child, I request authorization with the following code:
try await AuthorizationCenter.shared.requestAuthorization(for: .child)
For the parent, I show functions like:
familyActivityPicker
Are these settings automatically applied to the child's device, or do I need to send a silent push notification to apply the new settings? Additionally, how can I get statistics from the child's device to the parent's device?