Lock device, Restrict all apps | Screen Time API | iOS 16

Hi folks!

Is it possible to do next things using Screen Time API:

  1. Lock/Unlock device
  2. Restrict all apps
  3. Create schedule to lock/unlock device or restrict all apps, eg. lock all apps from Friday to Monday?

Thank you in advance!

Answered by Frameworks Engineer in 733313022
  1. 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.
  2. You cannot restrict all apps on the device, but you can shield all app and websites by setting both store.shield.applicationCategories and store.shield.webDomainCategories to the .all() ActivityCategoryPolicy. You can also block all webContent by setting webContent.blockedByFilter to the .all() WebContentSettings.FilterPolicy. See the ShieldSettings and WebContentSettings documentation for more information.
  3. 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

Accepted Answer
  1. 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.
  2. You cannot restrict all apps on the device, but you can shield all app and websites by setting both store.shield.applicationCategories and store.shield.webDomainCategories to the .all() ActivityCategoryPolicy. You can also block all webContent by setting webContent.blockedByFilter to the .all() WebContentSettings.FilterPolicy. See the ShieldSettings and WebContentSettings documentation for more information.
  3. 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

Would you be so kind to clarify one moment here...

You answered:

You cannot restrict all apps on the device, but you can shield all app

Can I block all apps instead of shield them?

Hello,

What if I want to set "usage limit" on selected apps, how can i achieve the setting usage limit action?

Lock device, Restrict all apps | Screen Time API | iOS 16
 
 
Q