Device Activity - DeviceActivitySchedule DateComponents intervals

Hi,

I'm having trouble understanding what is the correct DateComponents format for the DeviceActivityCenter.startMonitoring to work as expected.

Here's how it behaves with my setup:

  • The schedule interval is set for 15 minutes (the minimum).

  • On intervalDidStart I set the shields

shield.applicationCategories = .all(except: exclCat)
shield.webDomainCategories = .all(except: exclWeb)
  • On intervalDidEnd I clear the settings
shield.applicationCategories = nil
shield.webDomainCategories = nil

Different behavior with different DeviceActivitySchedule intervals. In the below examples I'll refer to hour, minute and second components as time components, and the calendar, timeZone, year, month, day, hour, minute and second components as date and time components.

Also, with all combinations below no errors are thrown when calling the startMonitoring method.


A. ❌ The start interval has time components, while the end interval has date and time components:

  • The intervalDidStart is not triggered.
DeviceActivitySchedule(schedule: <USDeviceActivitySchedule: 0x28354a5e0>
IntervalStart: <NSDateComponents: 0x2839c7f40> {
    Hour: 9
    Minute: 24
    Second: 55
IntervalEnd: <NSDateComponents: 0x2839c7f70> {
    Calendar: <CFCalendar 0x2818f9090 [0x1e4fb1d10]>{identifier = 'gregorian'}
    TimeZone: Asia/Manila (GMT+8) offset 28800
    Calendar Year: 2023
    Month: 5
    Leap Month: 0
    Day: 15
    Hour: 9
    Minute: 39
    Second: 55
Repeats: 0
WarningTime: (null))

B. ❌ The start interval has date and time components, while the end interval has time components:

  • Here, the opposite of the above example happens — the intervalDidStart is triggered, but the intervalDidEnd is not.

C. ❌ Both intervals have time components:

  • The intervalDidStart is not triggered.

D. ✅ Only hour, minute, and second components for both start and end intervals:

  • Callbacks are called as expected.
DeviceActivitySchedule(schedule: <USDeviceActivitySchedule: 0x282e80450>
IntervalStart: <NSDateComponents: 0x2822f39f0> {
    Hour: 9
    Minute: 12
    Second: 15
IntervalEnd: <NSDateComponents: 0x2822f3a00> {
    Hour: 9
    Minute: 27
    Second: 15
Repeats: 0
WarningTime: (null))

So it seems that the correct and working version is with the time components only.

However, from the documentation, the maximum schedule interval is a week. So if I need to set the schedule starting from a certain time of day A and ending in a certain time of day B, what should the DateComponents look like?

Thanks for you help!

I have the same problem... https://developer.apple.com/forums/profile/Kmart need help.

Hey, @tonyskansf did you manage to find a solution to your problem? I am facing the same issue...

Same here. @kmart any guidance?

This is still an issue with very unclear debugging steps or real clarity here. In the OP's case where you're trying to remove a shield at the end of the interval, we've noticed similar behavior that that intervalDidEnd isn't called until the user uses one of the tracked apps again (we're setting a schedule with specific DeviceActivityEvents), leading to odd behavior that doesn't allow understanding true device activity.

Same here! @Kmart can you please provide some guidance?

Device Activity - DeviceActivitySchedule DateComponents intervals
 
 
Q