One Logo Pool Ball
_DeviceActivity_SwiftUI · IOS API REFERENCE

DeviceActivityReport

struct · iOS 16.0+ · SDK 27.1

@MainActor @preconcurrency struct DeviceActivityReport

A view that reports the user's application, category, and web domain activity in a privacy-preserving way. When you create a report, the system asks your app's device activity report extension to provide a <doc://com.apple.documentation/documentation/swiftui/view> representing the user's device activity. To protect the user's privacy, your extension runs in a sandbox. This sandbox prevents your extension from making network requests or moving sensitive content outside the extension's address space. The extension point identifier for all device activity report extensions is `com.apple.deviceactivityui.report-extension`. You can configure a report with a custom context and filter, and then display the report like any SwiftUI view. struct ExampleView: View { let selectedApps: Set<ApplicationToken> let selectedCategories: Set<ActivityCategoryToken> let selectedWebDomains: Set<WebDomainToken> @State private var context: DeviceActivityReport.Context = .barGraph @State private var filter = DeviceActivityFilter( segment: .daily( during: Calendar.current.dateInterval( of: .weekOfYear, for: .now )! ), users: .children, devices: .init([.iPhone, .iPad]), applications: selectedApps, categories: selectedCategories, webDomains: selectedWebDomains ) public var body: some View { VStack { DeviceActivityReport(context, filter: filter) // A picker used to change the report's context. Picker(selection: $context, label: Text("Context: ")) { Text("Bar Graph") .tag(DeviceActivityReport.Context.barGraph) Text("Pie Chart") .tag(DeviceActivityReport.Context.pieChart) } // A picker used to change the filter's segment interval. Picker( selection: $filter.segmentInterval, label: Text("Segment Interval: ") ) { Text("Hourly") .tag(DeviceActivityFilter.SegmentInterval.hourly()) Text("Daily") .tag(DeviceActivityFilter.SegmentInterval.daily( during: Calendar.current.dateInterval( of: .weekOfYear, for: .now )! )) Text("Weekly") .tag(DeviceActivityFilter.SegmentInterval.weekly( during: Calendar.current.dateInterval( of: .month, for: .now )! )) } // ... } } } The system will only provide your extension with device activity data if the user has authorized your app for family controls on their device or on the device(s) of children in their iCloud family. See <doc://com.apple.documentation/documentation/familycontrols/authorizationcenter> for more details.

Members (1)

init · iOS 16.0+

init

TypeScript
static init(context: DeviceActivityReport_Context, filter?: _DeviceActivity_DeviceActivityFilter): Promise<DeviceActivityReport>
Swift declaration
@MainActor @preconcurrency init(_ context: DeviceActivityReport.Context, filter: DeviceActivityFilter = DeviceActivityFilter())

Creates a new device activity report. If you do not specify a filter, then the system will provide all device activity data for the current user and the current device to your device activity report app extension. - Parameters: - context: The context of the report. - filter: A filter for the device activity data that your app extension will use to render the report.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

DeviceActivityReport.body

This protocol needs associated types that cannot yet cross the bridge.

All _DeviceActivity_SwiftUI types →