DeviceActivityMonitor will automatically become invalid

I started monitoring using the following code:

deviceActivityCenter.startMonitoring(
          DeviceActivityName(name), 
          during: makeDailySchedule(), 
          events: events
)

Where:

DeviceActivitySchedule(
          intervalStart: DateComponents(hour: 0, minute: 0),
          intervalEnd: DateComponents(hour: 23, minute: 59),
          repeats: true,
          warningTime: nil
)

In DeviceActivityMonitor, I read and write data using UserDefaults and keep the logic minimal to ensure the size does not exceed 6MB. However, after a period of time, monitoring continues to fail. Why is this happening? How can I resolve this issue?

DeviceActivityMonitor will automatically become invalid
 
 
Q