最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xcode - Is there a way to call a function from the Shield Action Extension in the Main App? - Stack Overflow

programmeradmin1浏览0评论

So basically I was wondering if I could call a certain function from my Shield Action Extension, which is a built in feature of screen time api from Apple, in my Main App when for example a button is pressed.

class ShieldActionExtension: ShieldActionDelegate {
    var applicationProfile: ApplicationProfile!
    private var appStates: [ApplicationToken: Bool] = [:]
    
    override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
        let appIsUnlocked = appStates[application] ?? false
        switch action {
        case .primaryButtonPressed:
            createApplicationProfile(for: application)
            unlockAppAndStartTimer()
            completionHandler(.none)
        case .secondaryButtonPressed:
            sendShieldNotification(for: application)
            completionHandler(.defer)
            
        @unknown default:
            fatalError()
        }
    }
    
    func unlockAppAndStartTimer() {
        unlockApp()
        
        // Schedule timer to reshield after 15 minutes
        DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
            self.reapplyShield()
        }
    }
    
    
}

For example if I would like to call the function unlockAppAndStartTimer() when a button is pressed in a view in the Main Part of the app? I also already set up App Groups, however im not sure if this is relevant. My Main Problem is that the reshielding of apps only works in the background if I use the functions within the extension so I thought this idea of calling from somewhere else might be a fix?

发布评论

评论列表(0)

  1. 暂无评论