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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742343918a4426162.html
评论列表(0条)