One Logo Pool Ball
DeviceActivity · IOS API REFERENCE

DeviceActivityCenter

struct · iOS 15.0+ · SDK 27.1

struct DeviceActivityCenter

A class that enables an application's extension to start monitoring scheduled device activity. Activity begins when someone first uses a device within the scheduled time interval and ends when someone first uses the device outside of the interval. The system only invokes the ``DeviceActivity/DeviceActivityMonitor/intervalDidStart(for:)`` and ``DeviceActivity/DeviceActivityMonitor/intervalDidEnd(for:)`` when the device is in use. Likewise, the system invokes the ``DeviceActivity/DeviceActivityMonitor/eventDidReachThreshold(_:activity:)`` function when an event reaches its threshold.

Members (6)

get · iOS 15.0+

activities

TypeScript
get activities(): Array<DeviceActivityName>
Swift declaration
var activities: [DeviceActivityName] { get }

The activities that the application's extension currently monitors.

method · iOS 15.0+

stopMonitoring

TypeScript
stopMonitoring(activities?: Array<DeviceActivityName>): void
Swift declaration
func stopMonitoring(_ activities: [DeviceActivityName] = [])

Stops monitoring the specified device activities. This method ignores names that don't correspond to monitored activities. - Parameters: - activities: The names of the activities. If the array is empty or no `activities` are explicitly specified, this method stops monitoring all activities.

method · iOS 15.0+

startMonitoring

TypeScript
startMonitoring(activity: DeviceActivityName, schedule: DeviceActivitySchedule, events?: NativeMap<DeviceActivityEvent_Name, DeviceActivityEvent>): void
Swift declaration
func startMonitoring(_ activity: DeviceActivityName, during schedule: DeviceActivitySchedule, events: [DeviceActivityEvent.Name : DeviceActivityEvent] = [:]) throws

Starts monitoring the specified device activity. - Parameters: - activity: The name of the activity. - schedule: The schedule on which your app extension's ``DeviceActivityMonitor`` receives callbacks. - events: An optional mapping of events keyed by their names. If this parameter is empty, the application extension only receives callbacks for the start and end times of the schedule's interval. If the device's time zone changes in the middle of a schedule's interval, any ongoing events include device activity that may have accumulated outside of the new time zone. In other words, the system uses the time zone of the device at `nextInterval.start` to calculate device activity for the entirety of the interval. If the app already monitored the activity, this method overwrites the previous schedule and events. Attempting to monitor too many activities or activities that are too tightly scheduled can cause this method to throw an error. The system throws an error if the attempt to monitor the device activity failed. To avoid errors, reduce the number of unique, tightly-scheduled activities. For example, consider using the `warningTime` property of an activity's schedule. - Important: The application extension's ``DeviceActivityMonitor`` may begin receiving callbacks as soon as the system calls this method if the activity's scheduled interval is ongoing.

method · iOS 15.0+

events

TypeScript
events(activity: DeviceActivityName): NativeMap<DeviceActivityEvent_Name, DeviceActivityEvent>
Swift declaration
func events(for activity: DeviceActivityName) -> [DeviceActivityEvent.Name : DeviceActivityEvent]

Fetches the events of a device activity. The returned object is a static representation of the events at the time the function was called. In other words, an `Event` fetched for a particular activity doesn't dynamically update in response to future changes made to that activity. - Parameters: - activity: The name of the activity. - Returns: The events of the activity. The dictionary is empty if your app doesn't monitor the activity.

method · iOS 15.0+

schedule

TypeScript
schedule(activity: DeviceActivityName): (DeviceActivitySchedule) | null
Swift declaration
func schedule(for activity: DeviceActivityName) -> DeviceActivitySchedule?

Fetches the schedule of a device activity. The returned object is a static representation of the schedule at the time the function was called. In other words, a `Schedule` fetched for a particular activity doesn't dynamically update in response to future changes made to that activity. - Parameters: - activity: The name of the activity. - Returns: The schedule of the activity or `nil` if no such activity is currently monitored.

init · iOS 15.0+

init

TypeScript
static init(): DeviceActivityCenter
Swift declaration
init()

Creates an activity center to manage which device activities your application monitors. All instances are equivalent and manage the activities monitored by the application's extension.

Skipped declarations

No declarations were skipped in this snapshot.

All DeviceActivity types →