Contents

FamilyActivityPicker

A view in which users specify applications, web domains, and categories without revealing their choices to the app.

Declaration

@MainActor @preconcurrency struct FamilyActivityPicker

Overview

To prompt the user for their selection, create a binding to a FamilyActivitySelection instance, and use the binding to create a FamilyActivityPicker instance. You can then display the picker like any SwiftUI view.

struct ExampleView: View {
    @State var selection = FamilyActivitySelection()

    var body: some View {
        VStack {
            Image(systemName: "eye")
                .font(.system(size: 76.0))
                .padding()

            FamilyActivityPicker(selection: $selection)

            Image(systemName: "hourglass")
                .font(.system(size: 76.0))
                .padding()
        }
        .onChange(of: selection) { newSelection in
            let applications = selection.applications
            let categories = selection.categories
            let webDomains = selection.webDomains
        }
    }
}

To streamline this process, call the familyActivityPicker(isPresented:selection:) modifier on a view in your user interface. This modifier displays the picker view as a sheet over your user interface when the isPresented binding is true.

struct ExampleView: View {
    @State var selection = FamilyActivitySelection()
    @State var isPresented = false

   var body: some View {
       Button("Present FamilyActivityPicker") { isPresented = true }
       .familyActivityPicker(isPresented: $isPresented,
                             selection: $selection)
       .onChange(of: selection) { newSelection in
           let applications = selection.applications
           let categories = selection.categories
           let webDomains = selection.webDomains
       }
   }
}

When you present the FamilyActivityPicker, the system displays a view where the user can select categories, applications, and web domains. As soon as the user confirms their selection, the system updates the FamilyActivitySelection binding with the user’s selections. To protect the user’s privacy, the system uses opaque values to represent the selections.

Your app passes the selected values to the appropriate instances and methods from the Managed Settings and Device Activity frameworks.

Topics

Creating activity pickers

Accessing the content

Adding view modifiers

See Also

Activity selections