How to trigger intervalDidStart in DeviceActivity API?

I have followed the two videos about Screen time API in wwdc 21 and 22. Now i want to sheild some apps during sleeping, but I encounter some problems.

Problem I faced

  1. I write my monitor and override intervalDidStart and intervalDidEnd . Here is a simplified version
class Mymonitor: DeviceActivityMonitor {
  let store = ManagedSettingsStore()

  override func intervalDidStart(for activity: DeviceActivityName) {
      super.intervalDidStart(for: activity)
      store.shield.applications = selection.applicationToken
   }
  1. then I use deviceActivityCenter to start monitor
func StartSleep (_ startTime : DateComponents)
{
  let schedule = DeviceActivitySchedule(intervalStart: startTime,
                     intervalEnd: DateComponents(hour: 4, minute: 0),
                     repeats: true
                     )
  let center = DeviceActivityCenter()
  center.stopMonitoring([.daily])
  try! center.startMonitoring(.daily, during: schedule)
}

However, when I use StartSleep. The applications is not shielded. I have noticed that I haven't use Mymonitor in any place. In the demo Code, it seems i just need to finish two parts (DeviceActivityMonitor and DeviceActivityCenter).

But in the DeviceActivityCenter i do not use Mymonitor. Then how can i triggger intervalDidStart that i overwrited?

Do i miss other details. Where can i use Mymonitor?

Troubleshooting

  • I have successfully shield apps using store.shield.applications = selection,applicationToken directly.

Thanks for your reading and help!

It's tough to tell what exactly is going wrong without seeing your Xcode project, but two things that you might be missing are:

  1. Your Device Activity monitor app extension needs to have the Family Controls capability in order to use a ManagedSettingsStore.
  2. If you are attempting to share a FamilyActivitySelection between your app and your monitor extension, you will need to configure an App Group to do so. Otherwise, the selection.applicationToken you are using in Mymonitor will be empty.

If you are already doing the above, I'd recommend filing a bug report using Feedback Assistant and attaching your Xcode project so that we can take a look and offer more guidance.

Hello,

Have you find your solution? I am also facing the same issue.

How to trigger intervalDidStart in DeviceActivity API?
 
 
Q