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)
}