I am using Managed Settings to block all apps during a set period of time using the below method.
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
ManagedSettingsStore().shield.applicationCategories = .all()
}
When a user opens an app during that time, they should be allowed to press a button on the shield which lets them "continue using that app", just like the default iOS screen time allows for.
However, this doesn't seem possible right now when the below delegate is called for ActivityCategoryToken ShieldAction:
override func handle(action: ShieldAction, for category: ActivityCategoryToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
switch action {
case .primaryButtonPressed:
completionHandler(.close)
case .secondaryButtonPressed:
ManagedSettingsStore().shield.applicationCategories = .all(except: category) //this is not possible right now.
completionHandler(.none)
@unknown default:
fatalError()
}
}
This is because the .all(except:) method takes a set of application tokens, but the handle delegate method on activityCategoryTokens only provides application category tokens.
Is there no way to get around this? It would be very helpful if either
a) the delegate method for ActivityCategoryToken ShieldAction also provided the ApplicationToken that was blocked (this would be preferred), or
b) the .all(except: ) method also accepts ActivityCategoryTokens as an input.