Persist AppIntent after Force Quit?

I have implemented an AppIntent in my app with the purpose of allowing users to set up an automation within the Shortcuts app that runs based on a boolean value in my app.

It works well normally, but I've found that if my app is force quit, the Shortcut no longer works (presumably because it can't fetch the value of the boolean from my app anymore).

Does anyone know how to persist this value so that the Shortcut will work regardless of whether my app is open in the background?

Here is my implementation of the AppIntent:


struct my_automation: AppIntent {
    static var title: LocalizedStringResource = "Automation Name"
    
    var isTrue = UserDefaults.standard.bool(forKey: "myVal")
    
    func perform() async throws -> some IntentResult {
        return .result(value: isTrue)
    }
}

We just run into the same issue, trying to run the intent from Spotlight results in Shortcuts error notification and when running the intent from interactive widgets, only part of the logic gets executed 🤯

I would have guessed prior experiencing this, that triggering App Intent would launch the app if it were quit before.

Here is the error message from screenshot so others might perhaps find it:

"The operation couldn't be completed. (WFBackgroundShortcutRunnerErrorDomain error 1.)"

Persist AppIntent after Force Quit?
 
 
Q