Block a category using ManagedSettings

I'm trying to block the entire "social" category using ManagedSettings. However, the function blockApps does not work because of a compiler error on the let socialCategory = AcitivityCategoryToken line ("(Argument type '(UnboundedRange_) -> ()' does not conform to expected type 'Decoder')" and "Missing argument label 'from:' in call").

The code is the exact same as the WWDC 2022 (this video) but it still does not work.

import ManagedSettings

extension ManagedSettingsStore.Name {
    static let social = Self("social")
}

public class ScreenTimeApiModule: Module {
    public func definition() -> ModuleDefinition {
        Name("ScreenTimeApi")
        
        Function("blockApps") {
            let socialCategory = ActivityCategoryToken(...) //ERROR "(Argument type '(UnboundedRange_) -> ()' does not conform to expected type 'Decoder')" and "Missing argument label 'from:' in call"
            let socialStore = ManagedSettingsStore(named: .social)
            socialStore.shield.applicationCategories = .specific([socialCategory])
            print("Successfully blocked apps")
        }
    }
}

You cannot initialize an ActivityCategoryToken directly. Instead, you must utilize the FamilyActivityPicker and obtain your category tokens via a FamilyActivitySelection.

The example you provided is misleading for several reasons:

  • The ellipsis "..." likely implies that the developer needs to figure out the implementation. However, this approach is problematic since it's not feasible to generate an ActivityCategoryToken from scratch. One must either retrieve it through a FamilyActivitySelection or decode it from a Data object.
  • There's no method to determine if the ActivityCategoryToken instance you are dealing with belongs to the "Social" category. The only workaround would involve prompting the user to select the "Social" category in the FamilyActivityPicker and... trust him or her to do so.
Block a category using ManagedSettings
 
 
Q