Interact with ManagedSettingsStore from DeviceActivityMonitor

I want to remove shield restrictions for apps. Following the WWDC21 video, I declare ManagedSettingsStore and trying to reset restrictions:

class MyDeviceActivityMonitor: DeviceActivityMonitor {

    let store = ManagedSettingsStore()
 
    public override func intervalDidEnd(for activity: DeviceActivityName) {
        super.intervalDidEnd(for: activity)
     
        store.shield.applications = nil
    }
 }

Will this string has impact on the app store.shield.applications = nil? Because now, while testing it seems that I'm dealing with two different stores.

Or again it is doesn’t synced by default and let store = ManagedSettingsStore() will create store which will be different than store on which the app is relays on?

Thank you!

Starting in iOS 16, ManagedSettingsStores will share the same settings in the DeviceActivityMonitor extension as the host application. Meaning if you set a setting (like shield.applications) in ManagedSettingsStore() in the app, you will see the same setting in ManagedSettingsStore() in the extension. So, for example this will shield apps in the host application, and clear those same shields once the activity ends.

App:

func shieldApplications() {
    let selections = FamilyActivitySelection(includeEntireCategory: true)

    /* Get Application Tokens from FamilyActivityPicker */

    let store = ManagedSettingsStore()
    store.shield.applications = selections.applicationTokens
}

Extension:

class MyDeviceActivityMonitor: DeviceActivityMonitor {

    let store = ManagedSettingsStore()
 
    public override func intervalDidEnd(for activity: DeviceActivityName) {
        super.intervalDidEnd(for: activity)
     
        store.shield.applications = nil
    }
 }

If you do not want this behavior, please use the ManagedSettingsStore(named:) initializer instead, and use 2 differently named stores to keep the settings distinct from each other.

In iOS 15, stores are not shared between the host apps and extensions, so settings set by your app won't be seen in the extension and vice versa.

Systems Engineer, thank you for your reply!

Your example is exactly what I'm doing in the project. I'm using iOS 16.3.1 on the test device.


Tell me please, is there any possibility that version of: macOS, Xcode or Xcode command line tools could have impact on that behaviour?


I'm 100% sure I'm using single ManagedSettingsStore across the app. Btw, could you please share the link or some info in case we using store for iOS15? I'd like to see the mechanism of its synchronisation.

Thank you in advance!

Interact with ManagedSettingsStore from DeviceActivityMonitor
 
 
Q