类似“番茄todo”的学霸模式。可进行隐藏非系统级app, 阻止用户删除当前app(删除的时候会被移到资源库),阻止运行非系统级app
let store = ManagedSettingsStore()
//是否阻止用户删除当前app
store.application.denyAppRemoval = false
//限制选择的app
func setShieldRestrictions() {
//将selection从应用程序的模型中提取出来,并相应地配置应用程序屏蔽限制
let applications = MyModel.shared.selectionToDiscourage
store.shield.applications = applications.applicationTokens.isEmpty ? nil : applications.applicationTokens
store.shield.applicationCategories = applications.categoryTokens.isEmpty
? nil
: ShieldSettings.ActivityCategoryPolicy.specific(applications.categoryTokens)
selectionSet = applications.categoryTokens
}
//限制所有的app
func setShieldRestrictionsForAll() {
store.shield.applications = .none
store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.all()
}
import ManagedSettingsUI
阻止运行非系统级app后,点击app的时候弹出的屏蔽视图
let shieldConfig = ShieldConfiguration( backgroundBlurStyle: .light,backgroundColor: .red,icon: UIImage(named: "33.png"),title: ShieldConfiguration.Label(text: "hahha", color: .blue),subtitle: ShieldConfiguration.Label(text: "sub", color: .black),primaryButtonLabel: ShieldConfiguration.Label(text: "返回", color: .blue),primaryButtonBackgroundColor: .gray )
class ShieldConfigurationExtension: ShieldConfigurationDataSource {
override func configuration(shielding application: Application) -> ShieldConfiguration {
// Customize the shield as needed for applications.
// ShieldConfiguration()
return shieldConfig
}
override func configuration(shielding application: Application, in category: ActivityCategory) -> ShieldConfiguration {
// Customize the shield as needed for applications shielded because of their category.
return shieldConfig
}
override func configuration(shielding webDomain: WebDomain) -> ShieldConfiguration {
// Customize the shield as needed for web domains.
return shieldConfig
}
override func configuration(shielding webDomain: WebDomain, in category: ActivityCategory) -> ShieldConfiguration {
// Customize the shield as needed for web domains shielded because of their category.
return shieldConfig
}
}