startMonitoring(_:during:events:)
Starts monitoring the specified device activity.
Declaration
func startMonitoring(_ activity: DeviceActivityName, during schedule: DeviceActivitySchedule, events: [DeviceActivityEvent.Name : DeviceActivityEvent] = [:]) throwsParameters
- 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.startto calculate device activity for the entirety of the interval.
Discussion
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.