Hi folks!
Is it possible to do next things using Screen Time API
:
- Lock/Unlock device
- Restrict all apps
- Create schedule to lock/unlock device or restrict all apps, eg. lock all apps from Friday to Monday?
Thank you in advance!
- Locking and unlocking the device is not possible via the Screen Time API. If you'd like to see that capability in a future release, please file a report via Feedback Assistant.
- You cannot restrict all apps on the device, but you can shield all app and websites by setting both
store.shield.applicationCategories
andstore.shield.webDomainCategories
to the.all()
ActivityCategoryPolicy
. You can also block all webContent by settingwebContent.blockedByFilter
to the.all()
WebContentSettings.FilterPolicy
. See the ShieldSettings and WebContentSettings documentation for more information. - Yes you can create schedules via the Device Activity API. Here's a quick example on how to naively implement a schedule that shields all apps and websites for the weekend:
In the App:
extension DeviceActivityName {
static let weekend = Self("weekend")
}
let weekendSchedule = DeviceActivitySchedule(
intervalStart: DateComponents(calendar: calendar, hour: 0, minute: 0, weekday: 7),
intervalEnd: DateComponents(calendar: calendar, hour: 23, minute: 59, weekday: 1),
repeats: true,
warningTime: DateComponents(minute: 5)
)
do {
try deviceActivityCenter.startMonitoring(.weekend, during: weekendSchedule)
} catch {
// Handle the error.
...
}
In the DeviceActivityMonitor extension:
extension DeviceActivityName {
static let weekend = Self("weekend")
}
extension ManagedSettingsStore.Name {
static let weekend = Self("weekend")
}
func intervalDidStart(for activity: DeviceActivityName) {
if activity == .weekend {
// Shield all apps and websites
let store = ManagedSettingsStore(named: .weekend)
store.shield.applicationCategories = .all()
store.shield.webDomainCategories = .all()
}
}
func intervalDidEnd(for activity: DeviceActivityName) {
if activity == .weekend {
// Clear shields
let store = ManagedSettingsStore(named: .weekend)
store.clearAllSettings()
}
}
For more information, please refer to the DeviceActivity and ManagedSettings API documentation