DeviceActivityMonitor extension not running on device?

Hello friends,

I am working on an iOS app that uses the ScreenTime API to monitor app usage on the user's device.

I am able to set up the monitoring schedule and start monitoring using code like this in the application:

var calendar = Calendar.current

let startDateComps = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: startDate)
let endDateComps = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: endDate)

let schedule = DeviceActivitySchedule(intervalStart: startDateComps,
                                      intervalEnd: endDateComps,
                                      repeats: false)

let sessionName = DeviceActivityName(String(session.id))

do {
    try self.center.startMonitoring(sessionName, during: schedule)
}
catch {
    print("Could not start monitoring session \(sessionName): \(error)")
}

This appears to work. But in the DeviceActivityMonitor extension that I've added to the project, I never seem to get the init or intervalDidStart calls, and when I specify the DeviceActivityMonitor extension's scheme and try to debug it, XCode never seems to be able to attach to the DeviceActivityMonitor extension process (it shows "Waiting to attach" in the Debug navigator but never attaches), and I can't find the extension process when I manually try to attach to the process on the device.

I understand that the extension process isn't necessarily running all the time, but shouldn't we at least get the init call?

I think the extension was added to the project correctly, it shows up as a separate target in the project and also as an embedded appex in the main app target, and under the "Embed Foundation Extensions" build phase with the destination "Plugins and Foundation Extensions." I also added the extension and the main app to the same app group.

Also when I monitor the device I'm using for testing using the console, I don't see any mention of the DeviceActivityMonitor extension after the messages from installcoordinationd at install time.

Does anyone have any suggestions for how I could trouble-shoot this and figure out why the extension isn't running on the device?

i am on the same boat. Kindly let me know if you have figured this out

Has the issue been resolved?

DeviceActivityMonitor extension not running on device?
 
 
Q