Hello,
I've been trying to find answers to two specific issues related to the Screen Time API for several days now. I've gone through the Apple documentation and forums but have been unable to find concrete solutions.
The only suggestion I received from Mr. Kmart, an Apple staff member, was to implement a Device Activity Report that follows the DeviceActivityReportExtension protocol. However, no examples or clear instructions were provided, making it quite difficult to put this into practice.
**My Issues: **
How to restrict access to certain categories of apps for a child's device with a given time limit.
How to retrieve the Screen Time data for the child's apps.
I would be grateful if you could provide some code functions to assist me.
PS: It would be helpful if Apple could also publish the source code of the applications.
Thank you.
Post
Replies
Boosts
Views
Activity
Hello,
I would like to know if it is possible to extract or send data from the Device Activity Report Extension of a child phone to a parent phone (using a custom backend or not) with the child phone application.
Best regards,
Indigen
Hello,
I'm currently experiencing an issue with the DeviceActivityMonitor extension in my code, specifically with the eventDidReachThreshold callback. I'm hoping to get some insights into why this problem occurs and how to resolve it.
Problem:
Issue 1: The eventDidReachThreshold callback is not triggering as expected. It appears that the callback is not being invoked when the threshold is reached.
Issue 2: After a few seconds, the eventDidReachThreshold callback starts to trigger multiple times. This unexpected behavior is causing problems in my code, as it results in incorrect actions being taken.
iOS version: iOS16.7.2 and iOS17.1
Xcode version: 15.0.1
Swift version: 5.9
Here is my code to start the monitoring:
func startMonitoring() {
var startTime : DateComponents = DateComponents(hour: 0, minute: 0)
let endTime : DateComponents = DateComponents(hour: 23, minute: 59)
/// Creates the schedule for the activity, specifying the start and end times, and setting it to repeat.
let schedule = DeviceActivitySchedule(intervalStart: startTime, intervalEnd: endTime, repeats: true, warningTime: nil)
/// Defines the event that should trigger the encouragement.
let event = DeviceActivityEvent(applications: socialActivitySelection.applicationTokens, categories: socialActivitySelection.categoryTokens, webDomains: socialActivitySelection.webDomainTokens, threshold: DateComponents(minute: 2))
let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [.socialScreenTimeEvent : event]
do {
activityCenter.stopMonitoring([.socialScreenTime])
/// Tries to start monitoring the activity using the specified schedule and events.
try activityCenter.startMonitoring(.socialScreenTime, during: schedule, events: events)
} catch {
/// Prints an error message if the activity could not be started.
print("Could not start monitoring: \(error)")
}
}
If there are any known workarounds or potential solutions, please share them.
Thank you for your help in resolving this problem.