首页 > 解决方案 > Child 如何使用 Screen Time API 在一段时间内取消阻止应用程序

问题描述

我有一个在屏幕时间框架上运行的应用程序。现在在应用程序中,孩子可以自己阻止和取消阻止应用程序。而且我想知道如何一直阻止应用程序并仅在一段时间内取消阻止它们?假设 10 分钟。

我试过这个:

func unblockForMinute() {
        let applications = MyModel.shared.selectionToDiscourage // it's not the error, it's correct
        let center = DeviceActivityCenter()
        
        let schedule = DeviceActivitySchedule(
            intervalStart: DateComponents(hour: 8, minute: 00),
            intervalEnd: DateComponents(hour: 22, minute: 00),
            repeats: false
        )
        
        do {
            try center.startMonitoring(.unblock, during: schedule, events: [.encouraged: DeviceActivityEvent(
                applications: applications.applicationTokens,
                threshold: DateComponents(minute: 1)
            )])
            print("Unblock apps")
        } catch {
            print("Error")
        }
}

但这对我不起作用。谁能帮我?

标签: iosswiftswiftuiparent-childmdm

解决方案


推荐阅读