I have followed the two videos about Screen time API in wwdc 21 and 22. Now i want to sheild some apps during sleeping, but I encounter some problems.
Problem I faced
I write my monitor and override intervalDidStart and intervalDidEnd . Here is a simplified version
class Mymonitor: DeviceActivityMonitor {
let store = ManagedSettingsStore()
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
store.shield.applications = selection.applicationToken
}
then I use deviceActivityCenter to start monitor
func StartSleep (_ startTime : DateComponents)
{
let schedule = DeviceActivitySchedule(intervalStart: startTime,
intervalEnd: DateComponents(hour: 4, minute: 0),
repeats: true
)
let center = DeviceActivityCenter()
center.stopMonitoring([.daily])
try! center.startMonitoring(.daily, during: schedule)
}
However, when I use StartSleep. The applications is not shielded. I have noticed that I haven't use Mymonitor in any place. In the demo Code, it seems i just need to finish two parts (DeviceActivityMonitor and DeviceActivityCenter).
But in the DeviceActivityCenter i do not use Mymonitor. Then how can i triggger intervalDidStart that i overwrited?
Do i miss other details. Where can i use Mymonitor?
Troubleshooting
I have successfully shield apps using store.shield.applications = selection,applicationToken directly.
Thanks for your reading and help!
Topic:
App & System Services
SubTopic:
General
Tags:
Managed Settings
Family Controls
Screen Time
wwdc2022-10143