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
(the compiler errors are "(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) (at minute 5:30) but it still does not work.
import FamilyControls
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")
}
}
}
2
Answers
You’ve misunderstood the
...
here. It means "you need to get the ActivityCategoryToken normally." It does not mean "type dot-dot-dot."See FamilyActivitySelection for fetching the required token. You probably also want to go back to the Meet the Screen Time API video for more introduction.
The video you referenced is a "what’s new" video. It highlights new and changed features. It is not a full introduction to the topic.
The code shown on the slide is not complete. They are using an elipsis "…" to indicate that code has been omitted. In Swift it is used to indicate a range. By entering that verbatim you have a syntax error.
You cannot simply create an instance of an
ActivityToken
. You need to obtain tokens from aFamilyActivitySelection
that has been returned from the picker