Im new to coding so sry for the inconvenience. So principally I’ve this undertaking, in order that once I hit the first button of the protect configuration, that it sends a notification and likewise begins unshielding after which reshielding. nevertheless I carried out a guard Within the unshield and reshield perform in order that the Button from the view the place the notification results in, must be pressed first after which the unshielding and reshielding course of ought to begin. For the time being solely the notification works and nothing else will get executed after I hit the related button. Please assist I’ve been attempting to repair this for weeks…
class TimerManager: ObservableObject {
var isConfirmed = false
static let shared = TimerManager()
}
struct SwiftUIView: View {
let appToken: ApplicationToken
non-public let timerManager = TimerManager.shared
var physique: some View {
Button("Pause Defend for five Minutes") {
ButtonAction(for: appToken)
}
}
non-public func ButtonAction(for appToken: ApplicationToken) {
timerManager.isConfirmed = true
}
}
class ShieldActionExtension: ShieldActionDelegate {
override func deal with(motion: ShieldAction, for software: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
swap motion {
case .primaryButtonPressed:
sendShieldNotification(for: software)
attemptShieldModification(for: software)
completionHandler(.none)
case .secondaryButtonPressed:
completionHandler(.none)
@unknown default:
fatalError()
}
}
func attemptShieldModification(for software: ApplicationToken) {
let timerManager = TimerManager.shared
// Guard: Make sure the motion is confirmed earlier than continuing.
guard timerManager.isConfirmed == true else {
print("Motion not confirmed. Exiting perform.")
return // Exit if not confirmed
}
// Proceed with unlock and reapply protect as a result of the guard situation was met.
unlockApp(for: software)
reapplyShield(for: software)
// Reset affirmation after profitable operation.
timerManager.isConfirmed = false
print("Defend modification accomplished efficiently.")
}
}
I left some irrelevant stuff out. I at the moment have the goal membership for the Timermanager for Important App and the protect motion extension. I even have an app group which is shared between the primary app and the protect motion extension.