Time After (Screen) Time, part 1. The underworld of a barely known API.

letvar
3 min readMar 22, 2024

--

During the past weeks, we have worked for the first time with the Screen Time APIs on iOS. Unveiled at WWDC 2021 and updated in 2022, these APIs are helpful to interact with the Screen Time feature of iOS.

Working with these APIs has been quite challenging for several reasons, mostly because they lack of documentation and support articles, and also for their design built around privacy which brought us to think upside down several times to achieve our goals 🤯

In these articles, we will do an overview of all the lessons learned about these APIs, especially regarding the DeviceActivity framework, which is the one we used more.

Screen Time API 101

Screen Time APIs are built on top of the Screen Time feature of iOS, which is helpful to control the amount of time we spend in front of our devices, both for ourselves and for our kids.

These APIs are made of different frameworks working tightly together, namely ScreenTime, FamilyControls, ManagedSettings, ManagedSettingsUI and DeviceActivity.

Quickly summarizing, each framework covers a different part of Screen Time:

  • ScreenTime serves as a way for parents and guardians to supervise their children’s web usage, including web usage reporting, deletion of histroy and enforcing child restrictions. Despite its name, it’s not an entry point or an umbrella framework for the whole Screen Time feature.
  • FamilyControls allows parental control apps, and works seamlessly with Family Sharing in iOS. This API, especially requestAuthorization(for:), is needed to get access to other frameworks as well, for example DeviceActivity.
  • ManagedSettings and ManagedSettingsUI are used to restrict access to settings and features on the device, for example limiting media showing, restrict app purchases, or lock passcode settings.
  • DeviceActivity is used to monitor the activity of the user and to present reports. These activities include apps and categories of apps used, web domains, push notifications received and phone unlocks. In order to perform these actions, DeviceActivity provides two extensions — the Device Activity Monitoring and the Device Activity Report.

First of all: the Family Controls entitlement

In order to use the Screen Time APIs in your app, you have to request a special entitlement to Apple — the Family Controls entitlement. This is assigned on a case per case basis and you have to provide strong reasons in order to use it in your app. Just to make you understand the power of this entitlement: you can use it to prevent your app from being deleted, but only if you plan to use Screen Time features in your app (e.g. blocking distracting apps) and with a credible rationale (no, you can’t use it as an excuse to force users to stay in your app and increase KPIs, I’m sorry 😅).

The Family Controls entitlement for distribution can be requested by following this link. The entitlement is already available for debugging purposes in development by selecting it the Xcode capability tab of your target. Ask for the entitlement today, as requests are reviewed by the Apple Developer team and this process might take days, or even weeks.

Asking for permissions

Before using any framework of the Screen Time family, you should request authorization to use them. In order to do this, call requestAuthorization on the AuthorizationCenter shared instance. Authorization can be requested for the current .individual (yourself) or for a .child, in case of a Family Sharing account.

try await AuthorizationCenter.shared.requestAuthorization(for: .individual)

You can also choose to revoke the authorization, in case you don’t need it anymore:

AuthorizationCenter.shared.revokeAuthorization { result in
// handle revoke
}

The current authorization status can be accessed via the authorizationStatus property.

let currentStatus = AuthorizationCenter.shared.authorizationStatus

Stay tuned

The second part of this article will be published soon — stay tuned and make sure to follow our Medium and our social channels (@letvarhq)!

Photo by Aron Visuals on Unsplash

The author

Nicola Giancecchi
Co-founder, CEO and Apple Platforms Engineer @ letvar

Feedbacks are welcome! hello@letvar.io

--

--

letvar

We are a team of creatives and focused on crafting apps for any device.