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.

Replies

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.

  • Thank you for your answer. Is there any way to get Application Tokens from Category or something?

  • Thank you for the answer. I got an idea to solve the problem!

Add a Comment

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.

  • Hm, I can't get it to work, even with includeEntireCategory: true.

    It just shields all of my apps and ignores the "except" lol. My code looks like yours.

Add a Comment

Thanks for solving my current problem