How to shield the categories with Family Controls in iOS

I've implemented shielding apps with new Screentime API. But I don't know how to shield all categories app except the app selected by user in the FamilyActivityPicker? Here is my code to shield apps and it worked. But I want to know if I could shield all apps and all "categories" except the apps user selected. I want to allow only the apps and categories that user has selected.

let store = ManagedSettingsStore()
if let object = UserDefaults.standard.object(forKey: "SelectedAppTokens") as? Data {
    let decoder = JSONDecoder()
    if let appTokens = try? decoder.decode(Set<ApplicationToken>.self, from: object) {
        store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.all(except: appTokens)
    }
    
}

I save 'applicationTokens' from FamilyActivityPicker and shield with it.

I don't know much, as I've just started playing around with this stuff, but it looks like you're passing in a Set of Application Tokens instead of a Set of Application Categories.

I found a solution. I can get the Application Tokens from category when I set the option includeEntireCategory to true in FamilyActivitySelection.

like this

@State var selection = FamilyActivitySelection(includeEntireCategory: true)

If then, I can save the all application tokens(category include) selected by user.

Thanks for solving my current problem

Also note that when encoding/decoding with PropertyListEncoder, includeEntireCategory option is not encoded/decoded and decoded object is ALWAYS false.

How to shield the categories with Family Controls in iOS
 
 
Q