I'm very new to swift and I'm trying to make an app that disables user selected apps with the FamilyControls, ManagedSettings, Device Activity, and ManagedSettings UI frameworks. The code I've come up with so far is a combination of me looking at documentation and using chatgpt(not super helpful). The error that is the title of this post is what I get when I try to apply ShieldSettings to the applications, categories, and webdomains the user has selected. I'm sure I've done plenty of things wrong but would love some direction. The code is below
class Authorization {
let center = AuthorizationCenter.shared
func RequestAuthorization() async {
do {
try await center.requestAuthorization(for: FamilyControlsMember.individual)
} catch {
// handle errors
}
}
struct AppSelectionView: View {
@State var selection = FamilyActivitySelection()
@State var isPresented = false
var body: some View {
Button("Present FamilyActivityPicker") {isPresented = true}
.familyActivityPicker(isPresented: $isPresented, selection: $selection)
.onChange(of: selection, initial: true ) { newSelection,<#arg#> in
let applications = selection.applications
let categories = selection.categories
let webDomains = selection.webDomains
}
}
func applyRestrictions() {
let selectedApps = selection.applications
let selectedCategories = selection.categories
let selectedWebDomains = selection.webDomains
let appTokens = selectedApps.map{$0.token!}
let categoryTokens = selectedCategories.map {$0.token!}
let webDomainTokens = selectedWebDomains.map { $0.token!}
applyManagedSettings(for: appTokens, categories: categoryTokens, webDomains: webDomainTokens)
}
func applyManagedSettings(for appTokens: [ApplicationToken], categories: [ActivityCategoryToken], webDomains: [WebDomainToken]) {
ShieldSettings.applications = appTokens
ShieldSettings.applicationCategories = categories
ShieldSettings.webDomains = webDomains
}
}
}