Not getting call back to DeviceActivityMonitor extension

Hi,

Problem: Even after successful schedule creation I am not getting call backs(intervalDidStart, intervalDidEnd) to my extension

I have created DeviceActivityMonitor extension by creating call Directory Extension and updated info plist with the value (com.apple.deviceactivity.monitor-extension) and updated principal class value too.

I try running the extension on my demo app which has the below code,

        let schedule = DeviceActivitySchedule(

            intervalStart: DateComponents(hour: 10, minute: 30),

            intervalEnd: DateComponents(hour: 12, minute: 15),

            repeats: true,

            warningTime: nil)

        do {
            let center = DeviceActivityCenter()

            center.stopMonitoring([.daily])

            try center.startMonitoring(.daily, during: schedule)

            print("Schedule created")

            print(center.activities)

        } catch {
            print(error)
        }
    }

My extension has the below code,

override func intervalDidStart(for activity: DeviceActivityName) {

        super.intervalDidStart(for: activity)

        print("Entered Did Start")

    }

    override func intervalDidEnd(for activity: DeviceActivityName) {

        super.intervalDidEnd(for: activity)

        print("Entered Did End")

    }

Please guide me to find out the issue. Thanks in advance.

Answered by Rudraa in 686993022

Hi,

One of my friend suggested to debug extension process and check console which helped. I received the call back to the code and while observing console logs expected events fired for start and end. But I am not sure why print statement doesn't print any from extension principal class file.

Console logs under the process 'DeviceActivityMonitorExtension' below,

Interval started for daily

Interval ended for daily

Hope this will help.

Accepted Answer

Hi,

One of my friend suggested to debug extension process and check console which helped. I received the call back to the code and while observing console logs expected events fired for start and end. But I am not sure why print statement doesn't print any from extension principal class file.

Console logs under the process 'DeviceActivityMonitorExtension' below,

Interval started for daily

Interval ended for daily

Hope this will help.

Currently i have the same problem, I don't know why, but i can't get print statements in Monitor and it seem like methods are not running. Can you guid us what have you done to run this code?

Not getting call back to DeviceActivityMonitor extension
 
 
Q