Streaming is available in most browsers,
and in the Developer app.
-
What's new in Screen Time API
Find out how you can build apps that help people manage their relationship with their device — all while putting privacy first. We'll take you through the Screen Time API and share how you can use features like core restrictions and device activity reports to create great experiences while providing measurable control for the device's owner, parents, and guardians.
Resources
-
Download
♪ ♪ Hello, everyone, my name is MaryAshley Etefia, and I'm a software engineer for Screen Time. The COVID-19 pandemic put a lot of pressure on our industry to respond to the growing demand for digital health and productivity resources. The pandemic reinforced society's need for balance and has put everyone's ability to successfully manage their own space to the test. Last year, we introduced to you all the Screen Time API, which allowed you to build new apps to help your users manage their child's relationship with their device.
We were very pleased to see the creative and productive ways that you all have made use of our product. It excites us to see you embracing our culture of thinking differently. We are also very thankful for the feedback we have received in the past year. Before I introduce to you all what's new in iOS 16's ScreenTime API, I would first like to recap some highlights from our iOS 15 release.
Last year's Screen Time API introduced three new frameworks: Family Controls, Managed Settings, and Device Activity. In iOS 15, these frameworks brought new capabilities to your parental control apps. To jog your memory, let's take quick look at all three. Family Controls is essentially a gateway since it authorizes access to the Screen Time API. This framework allowed you to prevent removal of your parental control app, and it protected user privacy by providing opaque tokens used to identify apps and websites. With ManagedSettings, your app could apply restrictions, filter web traffic, and shield activity, much like Screen Time does, but customized with your app's branding and functionality.
The Device Activity framework allowed you to execute code on the start and end of timing windows, as well as whenever usage of an app or website exceeded a threshold.
Each of these three frameworks have had some exciting new updates in iOS 16.
These updates are not only going to make our API easier for you to use but are also going to enhance the experience of our users.
I'll walk you through the details using our demo application, Worklog.
Worklog encourages good habits for new professionals by restricting access to certain apps until a certain usage metric is met. I would like to show you how Aniyah, the owner of this iPhone, can impose these restrictions on herself using iOS 16's ScreenTime API.
Lets start with Family Controls.
If you remember from iOS 15, Family Controls was only capable of authorizing child devices via iCloud authentication.
We are happy to inform you that in iOS 16, Family Controls is now capable of authorizing independent users from their own device. This new authorization method means the Screen Time API can be used to build more than just parental controls apps. Unlike the existing parental control authorization, individual authorization can be used by any number of apps per device. Also, since individual authorization is not for parental control use cases, implicit restrictions for iCloud sign-out and deletion of an app do not apply. Let's look at how to use the new authorization.
The first thing your app needs to do on launch is request authorization for FamilyControls. I will use a shared Authorization Center to make this request when Worklog first launches. The request can either result in updating the authorization status or throwing an error.
Since this app has never been run on this iPhone before, requestAuthorization will ask for Aniyah's approval with an alert. Tapping on Allow will then prompt the user to authenticate with Face ID, Touch ID, or device passcode to continue. Once the user has successfully authenticated, calling requestAuthorization again will not prompt with an alert again, but instead silently succeed. Once an app has authorized with Family Controls, two switches are added in Settings for the app. One in Screen Time, under the Apps with Screen Time Access List and one in per app settings, labeled as Screen Time Restrictions. Parents and individual users can choose to deauthorize the app from Family Controls via either of these switches. As you can see, using the new individual authorization is just as simple as using the parental controls authorization, and we've made some nice improvements to both with our use of async. Now, lets look at the new changes to Managed Settings.
Managed Settings has been revamped to make developer use a lot more easy, particularly in the use of Managed Settings Store. For those of you who are unfamiliar, a Managed Settings Store is a data store that applies settings to the current user or device.
In iOS 15, you could only have one Managed Settings Store per process. Also, your app and device activity extensions had to have different Managed Settings Stores.
This made it difficult to change settings in response to device activity.
Now, in iOS 16, you can create up to 50 Managed Settings Stores per process, each with their own unique name. These named stores are also automatically shared between your app and all your app extensions. Also, you can now remove all the settings in any given named store all at once. I'd like to show you how Worklog uses named stores.
When Worklog launches for the first time and Aniyah's device has been successfully authorized, we create a Gaming ManagedSettingsStore.
This store will contain our gaming restrictions, which, in Worklog's case, includes shielding for all gaming websites.
Worklog also has a store named "Social" which shields social media apps and websites as soon as the app is launched for the first time. However, when using Worklog, Aniyah can click the Allow for Evenings button, which will create a Device Activity Schedule that only allows social media between 5:00 and 8:00 p.m. Once it's 5:00 p.m., our Device Activity Monitor un-restricts the corresponding named store.
When the timing window ends at 8:00 p.m., we re-apply restrictions to social media apps and websites on Aniyah's device. Now, some of you may be wondering, "Didn't our Gaming store restrict gaming websites?" "Won't clearing all the settings in our Social store conflict with our settings from our Gaming store?" The answer is no. The most restrictive setting always wins, therefore Gaming websites will still remain restricted on Aniyah's device. We feel that these new named stores are extremely powerful and will make it a lot simpler for you to develop apps using Managed Settings.
But we're not done yet. We've also added a very exciting feature to the Device Activity framework.
In iOS 15, Device Activity allowed your app to respond to the start and end of timing windows, as well as usage thresholds for apps and websites. In iOS 16, Device Activity has a new reporting service which enables your app to create completely custom usage reports using SwiftUI. The usage data is provided to a new extension point where you can customize which data is shown to the user, as well as how it's rendered on screen. These device activity reports allow for you to completely customize your user's experience, whilst providing the end user with complete privacy.
In Worklog, you can see us establish a DeviceActivityReport.Context and a DeviceActivityFilter. You can think of a DeviceActivityReport.Context as a customizable type that tells your report what type of view to draw based on DeviceActivity Data.
You can customize the timing windows of whichever report context by specifying a DeviceActivityFilter. We will then set the definition of our device activity report context inside of our DeviceActivityReportScene in order to tell the scene what to represent. Our content defines our custom configuration, PieChartView.Configuration, as well as the resulting SwiftUI view for this report. Then, inside of makeConfiguration, we will map over Aniyah's DeviceActivity Data, in order to hydrate our pie chart view's configuration. The framework will invoke makeConfiguration whenever new usage data is fetched so you do not need to invoke it yourself.
Here, you can see how PieChartView.Configuration serves as a view model for our pie chart view by providing the view with Aniyah's device activity data. Finally, we are able to render our custom SwiftUI report by defining it in the body of our DeviceActivityReport extension. The pie chart report that we created for Worklog is just one of the exciting ways that you can customize device activity reports.
That concludes our briefing of what's new to iOS 16's Screen Time API. As you can see, the Screen Time API continues to support features like core restrictions and device activity monitoring in the same secure yet privacy-preserving way that we first launched it. To recap, independent users can now authorize with Family Controls with the option of authorizing multiple third party applications per device, Managed Settings Stores now locally share settings between apps and their app extensions, and as a result, you are now allowed to manage multiple named stores in your application, and finally, the Device Activity framework is introducing a new privacy-preserving UI that reveals usage data to users and is customizable.
We believe that these new enhancements and additions will broaden the amount of users capable of engaging with your application. Thank you for inspiring this new release and thank you for your future contributions to the digital health and productivity space. We cannot wait to see the new and exciting ways that you make use of the Screen Time API. We welcome any feedback that you have and we will continue working to make this technology more accessible for you as well as our users. Thank you.
-
-
3:12 - Request aAhuthorization
// APP: Request Authorization import SwiftUI import FamilyControls @main struct Worklog: App { let center = AuthorizationCenter.shared var body: some Scene { WindowGroup { VStack {…} .onAppear { Task { do { try await center.requestAuthorization(for: .individual) } catch { print("Failed to enroll Aniyah with error: \(error)") } } } } }
-
5:13 - Managed settings store
// MONITOR EXTENSION: Handle Social category at start/end of interval import DeviceActivity import ManagedSettings class WorklogMonitor: DeviceActivityMonitor { let database = BarkDatabase() override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) let socialStore = ManagedSettingsStore(named: .social) socialStore.clearAllSettings() } override func intervalDidEnd(for activity: DeviceActivityName) { super.intervalDidEnd(for: activity) let socialStore = ManagedSettingsStore(named: .social) let socialCategory = database.socialCategoryToken socialStore.shield.applicationCategories = .specific([socialCategory]) socialStore.shield.webDomainCategories = .specific([socialCategory]) } }
-
7:02 - Device activity report and filter
// APP: Top-level view import SwiftUI import DeviceActivity extension DeviceActivityReport.Context { static let pieChart = Self(“Pie Chart") } @main struct Worklog: App { private let thisWeek = DateInterval(...) @State private var context: DeviceActivityReport.Context = .pieChart @State private var filter = DeviceActivityFilter(segment: .daily(during: thisWeek)) var body: some Scene { WindowGroup { GeometryReader { geometry in VStack(alignment: .leading) { DeviceActivityReport(context: context, filter: filter) .frame(height: geometry.size.height * 0.75) } }
-
7:24 - Device activity report
// REPORT EXTENSION: Configure Custom Device Activity Report import SwiftUI import DeviceActivity struct PieChartReport: DeviceActivityReportScene { let context: DeviceActivityReport.Context = .pieChart let content: (PieChartView.Configuration) -> PieChartView func makeConfiguration(representing data: [DeviceActivityData]) -> PieChartView.Configuration { var totalUsageByCategory: [ActivityCategory:TimeInterval] totalUsageByCategory = data.map(…) return PieChartView.Configuration(totalUsageByCategory: totalUsageByCategory) } }
-
7:55 - Configure Custom Device Activity Report
// REPORT EXTENSION: Configure Custom Device Activity Report import SwiftUI import DeviceActivity struct PieChartView: View { struct Configuration { let totalUsageByCategory: [ActivityCategory:TimeInterval] } let configuration: Configuration var body: some View { // A complex view that renders a bar graph based on Aniyah’s usage per category. PieChart(usage: configuration.totalUsageByCategory) } }
-
8:05 - Present custom report
// REPORT EXTENSION: Draw Custom Device Activity Report import SwiftUI import DeviceActivity @main struct WorklogReportExtension: DeviceActivityReportExtension { var body: some DeviceActivityReportScene { PieChartReport { configuration in PieChartView(configuration: configuration) } } }
-
-
Looking for something specific? Enter a topic above and jump straight to the good stuff.
An error occurred when submitting your query. Please check your Internet connection and try again.