Wednesday, December 7, 2022
HomeiOS DevelopmentApple Screentime API - iOS

Apple Screentime API – iOS

Does anybody have a pattern working code for the display screen time api? My app makes use of Household controls framework to get parental management authorisation. As soon as authorised, I create a schedule with occasions and begin monitoring it.

    var scheduleDuration = 60 //assumption
    for usageThreshold in stride(from: 1, to: scheduleDuration, by: 1) {
       let usageEvent1 = DeviceActivityEvent.init(threshold: .init(minute: usageThreshold))
       usageEvents[DeviceActivityEvent.Name.init(rawValue:"scheduleID~(usageThreshold)")] = usageEvent1

    let schedule = DeviceActivitySchedule(intervalStart: intervalStart, intervalEnd: intervalEnd, repeats: false)
    let activityName = DeviceActivityName.init(rawValue: "(scheduleID)")
    do {
        strive deviceActivityCenter.startMonitoring(activityName, throughout: schedule,occasions: usageEvents)
    }catch let error {
        NSLog("Error monitoring machine schedule - (error.localizedDescription)")

I’ve added DeviceActivityMonitor extension. It really works generally however all of a sudden cease receiving callbacks within the exercise monitor extension. Any assistance is appreciated 🙂



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments