How does child can unblock apps for some period of time using Screen Time API?

I have created the app that uses Screen Time API (Device Activity, Managed Settings and Family Control). I have allowed on child device block and unblock apps that are selected in familyPicker, but I have to add ability to unblock these apps for some period of time. I have tried this:

            do {

                    center.stopMonitoring()

                    try center.startMonitoring(.unblock, during: schedule, events: [.encouraged: DeviceActivityEvent(

                        applications: applications.applicationTokens,

                        threshold: DateComponents(second: 30)

                    )])

                    print("Unblock apps")

                } catch {

                    print("Error")

                }

Maybe I have to use another way to do it? but this doesn't work for me.

what your code actually says is: after 30 seconds of total usage of the application that you selected (applications.applicationTokens) the "eventDidReachThreshold" of the DeviceActivityMonitor extension will be called. handle your event ".encouraged" inside the "eventDidReachThreshold" and do there what ever you like.

i think for you case if you want to limit some apps for a period of time just make a scheduled event that start from the current time you tapped an OK button (or some other action) to current time + limitation time of tour choice. and on your DeviceActivityMonitor extension you should handle the blocking and unblocking on the intervalDidStart and intervalDidEnd

the your code should look something like this:

  do {       let schedule = DeviceActivitySchedule(intervalStart: start, intervalEnd: end, repeats: false, warningTime: nil)            try center.startMonitoring(.block, during: schedule)           } catch {       print("error: " + error.localizedDescription)     }

How does child can unblock apps for some period of time using Screen Time API?
 
 
Q