DeviceActivityMonitorExtension functions not being called

I'm having trouble with my DeviceActivityMonitorExtension. The intervalDidStart function is not being called when the scheduler is created. Does anyone have an idea why this is?

let schedule = DeviceActivitySchedule(
    intervalStart: DateComponents(hour: 15, minute: 23),
    intervalEnd: DateComponents(hour: 16, minute: 55),
    repeats: true
)

class MySchedule {
    static public func setSchedule() {
        let center = DeviceActivityCenter()
        center.stopMonitoring([.daily])
        do {
            try center.startMonitoring(.daily, during: schedule)
        } catch {
            print("Error monitoring schedule: ", error)
        }
    }
}
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
    override func intervalDidStart(for activity: DeviceActivityName) {
        super.intervalDidStart(for: activity)
        SelectedApps.shared.setRestrictions()
    }
private let _SelectedApps = SelectedApps()

class SelectedApps: ObservableObject{
    @Published var selection: FamilyActivitySelection
    
    let store = ManagedSettingsStore()
    
    init() {
        if let savedSelection = UserDefaults.standard.object(forKey: "savedSelection") as? Data {
            let decoder = JSONDecoder()
            if let loadedSelection = try? decoder.decode(FamilyActivitySelection.self, from: savedSelection) {
                selection = loadedSelection
            } else {
                selection = FamilyActivitySelection(includeEntireCategory: true)
            }
        } else {
            selection = FamilyActivitySelection(includeEntireCategory: true)
        }
        
    }
    
    class var shared: SelectedApps {
        return _SelectedApps
    }
    
    
    func setRestrictions(){
        let applications = selection
        
        store.shield.applications = applications.applicationTokens.isEmpty ? nil : applications.applicationTokens
        store.shield.applicationCategories = applications.categoryTokens.isEmpty
        ? nil
        : ShieldSettings.ActivityCategoryPolicy.specific(applications.categoryTokens)
        
    }
Accepted Answer

Realized that I wasn't sharing data between my app and extension properly.

I had a similar problem for a couple of days. What fixed it for me is implied from this answer: I had to put them both in an App Group. I also had to send push notifications, as the print statements weren't printing to the console. Hope this helps someone!

the same issue i am facing from last some days is there any other approach to get the tokens in extension group

DeviceActivityMonitorExtension functions not being called
 
 
Q