ScreenTime API

Can the Screen Time API in iOS be used to block specific applications or application categories from getting launched? I went through the documentation here: https://developer.apple.com/videos/play/wwdc2022/110336/ and it indicates that we should be able to block certain app categories using the DeviceActivity and FamilyControl Framework.

So, I created the following code snippet: class DeviceActivityMonitorExtension: DeviceActivityMonitor {

    let store = ManagedSettingsStore()

        override func intervalDidStart(for activity: DeviceActivityName) {

            super.intervalDidStart(for: activity)

            NSLog("interval did start")

            let model = MyModel.shared

            let applications = model.selectionToDiscourage.applicationTokens

            store.shield.applications = applications.isEmpty ? nil : applications

            store.dateAndTime.requireAutomaticDateAndTime = true

        }

And made a class model

 var selectionToDiscourage = FamilyActivitySelection() {

        willSet {

            NSLog ("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.webDomains = webCategories

        }

    }

I expected it to block the launch of any application, but it does not happen.

Any idea what I might be missing here? I have already added Family Controls capability to my application. Do I need any others?

Replies

In order to use the DeviceActivity and/or ManagedSettings frameworks, your app not only needs the Family Controls capability, but it also needs to request authorization with the FamilyControls framework. Also, there is a difference between "shielding" and "blocking" apps with ManagedSettings. Shielding an application will not prevent it from launching, instead it will cause a shield to be overlayed on top of the app. Blocking an app will hide it from the home screen and prevent the user from launching it.

Thank you for the reply but I have already added authorization which are needed but still can't able to get desired result.