-2.2 C
New York
Wednesday, January 8, 2025

ios – How do I unshield and defend apps with Display Time API?


So I already made it attainable to unshield and defend a particular app when you hit the first button of the defend configuration.

class ShieldActionExtension: ShieldActionDelegate {
    override func deal with(motion: ShieldAction, for utility: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
        swap motion {
        case .primaryButtonPressed:
            
            unlockandreapply(for: utility)
            completionHandler(.none)
        case .secondaryButtonPressed:
            
            completionHandler(.none)
        @unknown default:
            fatalError()
        }
    }
    
    func unlockandreapply(for utility: ApplicationToken)
    {
        unlockApp(for: utility)
        
        // Schedule timer to reshield after 10 seconds
        DispatchQueue.major.asyncAfter(deadline: .now() + 10) {
            self.reapplyShield(for: utility)
            
            
        }
    }
    personal func unlockApp(for utility: ApplicationToken) {
        let retailer = ManagedSettingsStore()
        retailer.defend.functions?.take away(utility)
        print("App (utility) is unshielded")
    }
    
    // Reapplies the defend to the applying
    personal func reapplyShield(for utility: ApplicationToken) {
        let retailer = ManagedSettingsStore()
        
        // Create a brand new defend configuration if essential
        if retailer.defend.functions == nil {
            retailer.defend.functions = [application]
        } else {
            retailer.defend.functions?.insert(utility)
        }
        print("Protect reapplied to utility with token (utility)")
    }
} 

Nonetheless is it attainable to unshield and defend apps exterior of The Protect motion extension? Till now I might solely get the unshielding to work exterior of the extension, however the reshielding by no means labored within the background, this solely labored inside the extension. My purpose is to have a button in my very own app which then might unshield and reshield completely within the background identical to my present major button of the defend configuration…

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles