ios - 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")
}
}
但这对我不起作用。谁能帮我?
解决方案
推荐阅读
- c++ - 在 main.cpp 中使用模板关键字时出现“带有 C 链接的模板”错误
- templates - UWP - 具有两个不同来源的 NavigationView
- pine-script - 即使再次满足相同的条件,也保持一个值
- python - 为什么pygame绘图仅在窗口被拖出屏幕后才出现?
- python - Python3 – 在 f 字符串中用 \n 分隔的打印列表
- javascript - 如何以一种形式验证 3 个 div 代码?
- javascript - 无法读取未定义 Angular 6 的属性“替换”
- git - 如何删除文件夹中标记为未添加到git的所有文件?(很多被删除的文件在切换分支后又出现了)
- linux - grep "fixme" 和 "fix me" 然后 cat 生成单个文件
- android - 功能异常