One Logo Pool Ball
DeviceActivity · IOS API REFERENCE

DeviceActivitySchedule

struct · iOS 15.0+ · SDK 27.1

struct DeviceActivitySchedule

A calendar-based schedule for when to monitor a device's activity. Create a new schedule using `DateComponents` that allows your app to monitor the person's device activity during a period of time. You can set a schedule for your app to monitor on a regularly occuring basis. You can create a warning time that the system uses to provide your app extension with callbacks whenever a schedule is about to start or end, or when an event is close to reaching its threshold.

Members (6)

get · iOS 15.0+

intervalEnd

TypeScript
get intervalEnd(): _Foundation_DateComponents
Swift declaration
var intervalEnd: DateComponents { get }

The date components that represent the end time for a schedule's interval. The system uses these components to compute `nextInterval.end`.

get · iOS 15.0+

warningTime

TypeScript
get warningTime(): (_Foundation_DateComponents) | null
Swift declaration
var warningTime: DateComponents? { get }

Optional components that generate a warning prior to regularly scheduled events. You can create a warning time to notify your app extension ahead of time before the scheduled activity begins and ends. For instance, when your app schedules activity-monitoring from 10 a.m. to 11 a.m. for an event with a 30-minute threshold, setting the schedule's warning time to 5 minutes results in the extension receiving ``DeviceActivity/DeviceActivityMonitor/intervalWillStartWarning(for:)``, ``DeviceActivity/DeviceActivityMonitor/intervalWillEndWarning(for:)``, and ``DeviceActivity/DeviceActivityMonitor/eventWillReachThresholdWarning(_:activity:)`` callbacks at 9:55 a.m., 10:55 a.m, and when 25 minutes of the event's activity occurs, respectively. If the components specify a longer time interval than the schedule's interval, the system clamps the warning callbacks for each event's threshold to the start time of the interval.

get · iOS 15.0+

nextInterval

TypeScript
get nextInterval(): (_Foundation_DateInterval) | null
Swift declaration
var nextInterval: DateInterval? { get }

The schedule's next interval or the current interval if one is ongoing. `nil` if `intervalStart` and `intervalEnd` don't match any future dates. The start and end dates indicate the earliest point when the ``DeviceActivity/DeviceActivityMonitor/intervalDidStart(for:)`` and ``DeviceActivity/DeviceActivityMonitor/intervalDidEnd(for:)`` methods of your app extension's principal class invokes. The system actually invokes these methods when someone uses the device during the interval. The system additionally calls ``DeviceActivity/DeviceActivityMonitor/intervalDidEnd(for:)`` when you stop monitoring an activity with an ongoing interval. The system doesn't call these methods unless the device is used during the interval. - Note: This interval is computed using the provided date components and the <doc://com.apple.documentation/documentation/foundation/Calendar/MatchingPolicy/nextTimePreservingSmallerComponents> policy for the `calendar` of both date components. If you don't specify a calendar for either components, the system uses `Calendar.current`. The system bases the interval's end date on wall-clock time, regardless of any time zone changes that occur during the interval.

init · iOS 15.0+

init

TypeScript
static init(intervalStart: _Foundation_DateComponents, intervalEnd: _Foundation_DateComponents, repeats: boolean, warningTime?: (_Foundation_DateComponents) | null): DeviceActivitySchedule
Swift declaration
init(intervalStart: DateComponents, intervalEnd: DateComponents, repeats: Bool, warningTime: DateComponents? = nil)

Creates a new schedule. - Important: If the current date falls in between ``intervalStart`` and ``intervalEnd``, the system calls the ``DeviceActivity/DeviceActivityMonitor/intervalDidStart(for:)`` method immediately upon starting to monitor the activity. If the current date doesn't fall in between `intervalStart` and `intervalEnd`, then `intervalDidStart(for:)` calls at the next date matching `intervalStart`. - Parameters: - intervalStart: The date components that represent the start time for a schedule's interval. - intervalEnd: The date components that represent the end time for a schedule's interval. - repeats: Indicates whether the schedule recurs. If `false`, the extension stops receiving callbacks when the interval ends for the first time. - warningTime: An optional warning time to receive callbacks. If the components specify a longer time interval than the schedule's interval, the system clamps the warning callbacks for each event's threshold to the start time of the interval.

get · iOS 15.0+

intervalStart

TypeScript
get intervalStart(): _Foundation_DateComponents
Swift declaration
var intervalStart: DateComponents { get }

The date components that represent the start time for a schedule's interval. The system uses these components to compute `nextInterval.start`.

get · iOS 15.0+

repeats

TypeScript
get repeats(): boolean
Swift declaration
var repeats: Bool { get }

A Boolean value that indicates whether the schedule recurs. Use `repeats` to create an activity schedule that repeats until the activity-monitoring stops.

Skipped declarations

No declarations were skipped in this snapshot.

All DeviceActivity types →