So I already made it doable to unshield and protect a particular app when you hit the first button of the protect configuration.
class ShieldActionExtension: ShieldActionDelegate {
override func deal with(motion: ShieldAction, for software: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
change motion {
case .primaryButtonPressed:
unlockandreapply(for: software)
completionHandler(.none)
case .secondaryButtonPressed:
completionHandler(.none)
@unknown default:
fatalError()
}
}
func unlockandreapply(for software: ApplicationToken)
{
unlockApp(for: software)
// Schedule timer to reshield after 10 seconds
DispatchQueue.most important.asyncAfter(deadline: .now() + 10) {
self.reapplyShield(for: software)
}
}
non-public func unlockApp(for software: ApplicationToken) {
let retailer = ManagedSettingsStore()
retailer.protect.purposes?.take away(software)
print("App (software) is unshielded")
}
// Reapplies the protect to the applying
non-public func reapplyShield(for software: ApplicationToken) {
let retailer = ManagedSettingsStore()
// Create a brand new protect configuration if mandatory
if retailer.protect.purposes == nil {
retailer.protect.purposes = [application]
} else {
retailer.protect.purposes?.insert(software)
}
print("Defend reapplied to software with token (software)")
}
}
Nonetheless is it doable to unshield and protect apps outdoors of The Defend motion extension? Till now I may solely get the unshielding to work outdoors of the extension, however the reshielding by no means labored within the background, this solely labored inside the extension. My aim is to have a button in my very own app which then may unshield and reshield completely within the background identical to my present major button of the protect configuration…