I have next flow:
- User selects apps to discourage
- Then user selects apps with permanent access. To do this, the app blocks all apps, and then user selects which apps should be unblocked back.
I've created two ManagedSettingsStore
s. At the step 1, I put apps in store 1, at the step 2 I put apps in store 2.
To block all apps at step 2 I do:
store.shield.applicationCategories = .all()
After that I'm expecting that store.shield.applications
will contain all apps that user has blocked at the step 2. I want to filter blocked apps on step 1 and step 2.
But it doesn’t happen. Instead I see just one general token for all blocked apps.
How I can receive Set<ApplicationToken>
from ShieldSettings.ActivityCategoryPolicy<Application>
?
The ManagedSettingsStore
only reports back the settings that have been set by your authorized application. So for example, if the application sets the .all()
policy for store.shield.applicationCategories
(like so store.shield.applicationCategories = .all()
), then the store will report back that it has set it the .all()
policy when queried again. Similarly, if the app doesn't set the value of store.shield.applications
, then the store will also not report anything back when queried.
Both the shield.applicationCategories
and shield.applications
are separate settings that work in tandem to allow authorized applications to shield apps. shield.applicationCategories
lets the authorized application shield other applications based on their category with specific exceptions, whereas shield.applications
allows it to shield specific applications instead of by category.
In order to get a list of installed applications on the device, as well as generate ApplicationTokens, the authorized application can use the FamilyActivityPicker, to allow users to make the selection they desire while maintaining their privacy. The selected applications will be stored in the FamilyActivitySelection object used to initiate the picker (be sure to use init(includeEntireCategory: true)
if you'd like all application tokens in a category if the category is selected).
I should also note that an instance of a ManagedSettingsStore cannot cause another store to be less restrictive. For example, if you have a store (store1) that sets store1.shield.applicationCategories = .all()
, no matter what you set in store2, it cannot cause the policy to be less restrictive than .all()
, since that's the most restrictive policy we have for shield.applicationCategories
. So in order to block all apps except for apps that the user selects, it should all be done in a single store in a single policy like so:
let exceptions = selection.applicationTokens // apps selected in FamilyActivityPicker
store.shield.applicationCategories = .all(except:exceptions)