DeviceActivityCenter.startMonitoring occasionally crash in the morning

When I use the screen time API, the app occasionally crashes in the morning. I mean the UI freeze lasts for more than ten seconds.

But the weird thing is that I work normally during the day, that is, in the morning, when I just woke up. (There is no Do Not Disturb mode). This problem has been bothering me for several days, please help.

The specific crash log is as follows, and the specific code is as follows.

Model: iPhone 15 Pro, iOS: 18.1.1

Thanks for your help!

Code:

private func startAppMonitoring(application: ApplicationToken, seconds: Int, isFromNow: Bool) {
        let schedule = DeviceActivitySchedule(
            intervalStart: isFromNow ? Calendar.current.dateComponents([.hour, .minute, .second], from: Date()) : DateComponents(timeZone: TimeZone(identifier:TimeZone.current.identifier), hour: 0, minute: 0, second: 0),
            
            intervalEnd: DateComponents(timeZone: TimeZone(identifier:TimeZone.current.identifier), hour: 23, minute: 58, second: 59),
            repeats: true,
            warningTime: DateComponents(minute: 1)
        )
        
        let event = DeviceActivityEvent(
            applications: Set([application]),
            threshold: DateComponents(second: seconds)
        )
        
        let center = DeviceActivityCenter()
        
        do {
            try center.startMonitoring(DeviceActivityName("\(application.hashValue)Usage"), during: schedule, events: [DeviceActivityEvent.Name("\(application.hashValue)Event"): event])
        } catch {
            print("Error starting monitoring schedule: \(error)")
        }
    }

Crash report:

I'm unable to work with this crash report as I need to see the complete Apple crash report with its original formatting preserved. Please post the complete Apple crash report as an attachment to preserve its formatting. Posting a Crash Report explains how to do so.

Thanks for the reply, the attachment has been added.

DeviceActivityCenter.startMonitoring occasionally crash in the morning
 
 
Q