Device Activity Monitor Extension behaves randomly - any idea?

Hello, I'm working on an app that makes use of Screen Time features by leveraging the Family Controls, Device Activity and Managed Settings frameworks.

The main app works fine by shielding/unshielding apps with a toggle.

When it comes to monitoring the time intervals with the Device Activity Monitor (DAM) extension (e.g. lock X apps for Y minutes), I'm experiencing several issues.

To shield/unshield apps and kick off the monitoring I perform the following instructions:

let timeInMinutes = 15
let startDate = Date(timeIntervalSinceNow: 1.0) // padding added to avoid invalid DAM ranges < 15 mins.
let endDate = startDate.addingTimeInterval(timeInMinutes * 60.0)

let components: Set<Calendar.Component> = [.day, .month, .year, .hour, .minute, .second]
let calendar = Calendar.current
let intervalStart = calendar.dateComponents(components, from: startDate)
let intervalEnd = calendar.dateComponents(components, from: endDate)

let schedule = DeviceActivitySchedule(intervalStart: intervalStart, intervalEnd: intervalEnd, repeats: false)
try deviceActivityCenter.startMonitoring(.definiteShield, during: schedule)

let managedSettingsStore = ManagedSettingsStore()
managedSettingsStore.shield.applications = selection.applicationTokens // `selection` being an instance of `FamilyActivitySelection` 

The main pain points are:

  1. After this code is performed, I would expect the Device Activity Monitor extension to start, or at least to start once I go to background. To check whether the DAM extension is running or not, I attach to the extension process manually (Product > Attach to Process by PID or Name). But I can see the extension correctly running only after 3-4 attempts of calling startMonitoring.
  2. Even when the DAM extension runs, intervalDidStart and intervalDidEnd methods in the extension are called quite randomly - most of the times not being called at all - thus making the extension hugely unaffordable.

Please note:

  • I already ask for Screen Time permissions during the onboarding by calling AuthorizationCenter.shared.requestAuthorization(for: .individual), so by the time the user shields the apps, these permissions are already granted.
  • I already have Family Control entitlements for development and distribution, and for both the main target and the DAM extension target.
  • In the intervalDidEnd method, I simply call ManagedSettingsStore().clearAllSettings() and DeviceActivityCenter().stopMonitoring(). This looks like to be enough to stay way below the 6MB memory limit.

Am I doing something wrong, is there a way to fix this, or is just the Device Activity framework that is unstable?

Answered by Engineer in 791673022

This is a known issue, please file a Bug Report.

I am having same issues with it's instability. Do you know how we can reach out to apple to get a fix on iOS 18? Also, if you figure anything out please let me know.

Accepted Answer

This is a known issue, please file a Bug Report.

FB14414545 - Good luck!

Filed FB15012461

I'm also struggling with calling the extension, but in my case I don't think its working at all. When you say you can shield apps with a toggle, are you doing that in your main app? I was under the impression that shielding had to be done in the extension by calling center.startMonitoring(), but if it can be done without it I think that would be fine for my purposes. If you have any insight on this, it would be greatly appreciated!

Device Activity Monitor Extension behaves randomly - any idea?
 
 
Q