I added the extension via targets. And I added code in the intervalDidStart() override to print and send a notification. But it never seems to run. Am I supposed to do any other steps after adding the extension?
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
func getSelectionFromUserDefaults() -> FamilyActivitySelection {
let defaults = UserDefaults.standard
if let encodedData = defaults.data(forKey: "ScreenTimeSelection") {
let decoder = PropertyListDecoder()
if let selection = try? decoder.decode(FamilyActivitySelection.self, from: encodedData) {
return selection
}
}
return FamilyActivitySelection()
}
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
print("HERE!")
let content = UNMutableNotificationContent()
content.title = "Feed the cat"
content.subtitle = "It looks hungry"
content.sound = UNNotificationSound.default
// show this notification five seconds from now
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
// add our notification request
UNUserNotificationCenter.current().add(request)
let selection = getSelectionFromUserDefaults()
let applications = selection.applicationTokens
let categories = selection.categoryTokens
let webCategories = selection.webDomainTokens
let store = ManagedSettingsStore()
store.shield.applications = applications.isEmpty ? nil : applications
store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set())
store.shield.webDomainCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set())
}