I've setup screen time api with encouraged & discouraged apps and monitoring apps.
var selectionToDiscourage = FamilyActivitySelection() {
willSet {
print ("got here \(newValue)")
let applications = newValue.applicationTokens
let categories = newValue.categoryTokens
//let webCategories = newValue.webDomainTokens
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())
}
}
let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [
.encouraged: DeviceActivityEvent( applications: selectionToDiscourage.applicationTokens, threshold: DateComponents(minute: 10))
]
print ("Could not start monitoring \(selectionToDiscourage)")
let center = DeviceActivityCenter()
center.stopMonitoring()
do {
try center.startMonitoring(.daily, during: schedule, events: events)
}
catch {
print ("Could not start monitoring \(error)")
}
extension DeviceActivityName {
static let daily = Self("daily")
}
@available(iOS 15.0, *)
extension DeviceActivityEvent.Name {
static let encouraged = Self("encouraged")
}
ideally once the encouraged apps reaches 10mins screentime I should have received an event in DeviceActivityMonitorExtension. However i am not receiving any event here.
super.eventDidReachThreshold(event, activity: activity)
print("eventDidReachThreshold", event)
store.shield.applications = nil
store.shield.applicationCategories = nil
// Handle the event reaching its threshold.
}
Please help.